Type error in `IN` clause in postgreSQL using `$queryRaw` when upgrading to v4
See original GitHub issueBug description
There seems to be a regression regarding IN
clauses in postgreSQL in prisma v4.
The issue happened on postgresql and the behaviour changed somewhere between prisma 3.15.2
and 4.2.1
.
For a given table of this structure:
CREATE TABLE repro(
`id` UUID NOT NULL PRIMARY KEY,
)
When querying a list of rows using an IN query clause like so:
const rows = await this.prismaClient.$queryRaw<
{ id: string }[]
>(Prisma.sql`
SELECT id
FROM repro
WHERE id IN (${Prisma.join(ids)});
`)
This worked fine in 3.15.2
but returns a type error in 4.2.1
:
{
"code": "P2010",
"clientVersion": "4.2.1",
"meta": {
"code": "42883",
"message": "db error: ERROR: operator does not exist: uuid = text\nHINT: No operator matches the given name and argument types. You might need to add explicit type casts."
}
}
I’ve tried different castings but nothing seemed to work.
This query works on the other hand:
const rows = await this.prismaClient.$queryRaw<
{ id: string }[]
>(Prisma.sql`
SELECT id
FROM repro
WHERE id = ANY (ARRAY[${Prisma.join(ids)}]::uuid[]);
`)
I haven’t seen what would cause this in the upgrade guide and it does look like a regression to me. I’m guessing there’s a change in how the casting is done which broke this query.
How to reproduce
A reproduction repository is available here: https://github.com/floriantz/repro-prisma
Expected behavior
The query should not cause an error
Prisma information
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgres"
url = "postgres://postgres:postgres@localhost:5432/postgres"
}
model repro {
id String @id @db.Uuid
}
Environment & setup
- OS: MacOS 12.2.1
- Database: PostgreSQL
- Node.js version: 16+
Prisma Version
prisma : 4.2.1
@prisma/client : 4.2.1
Current platform : darwin-arm64
Query Engine (Node-API) : libquery-engine 2920a97877e12e055c1333079b8d19cee7f33826 (at node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Migration Engine : migration-engine-cli 2920a97877e12e055c1333079b8d19cee7f33826 (at node_modules/@prisma/engines/migration-engine-darwin-arm64)
Introspection Engine : introspection-core 2920a97877e12e055c1333079b8d19cee7f33826 (at node_modules/@prisma/engines/introspection-engine-darwin-arm64)
Format Binary : prisma-fmt 2920a97877e12e055c1333079b8d19cee7f33826 (at node_modules/@prisma/engines/prisma-fmt-darwin-arm64)
Default Engines Hash : 2920a97877e12e055c1333079b8d19cee7f33826
Studio : 0.469.0
Issue Analytics
- State:
- Created a year ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
postgres bind parameters not supported with Prisma v4 client ...
Bug description after upgrading to the prisma v4 client I'm not able to execute a postgres insert statement that uses bind parameters which...
Read more >Prisma $queryRaw with variable length parameter list
$queryRaw`select * from users where id in (${join(ids)})`;. but this throws the same error. any Idea how I can achieve this? postgresql ·...
Read more >Documentation: 15: Appendix A. PostgreSQL Error Codes
All messages emitted by the PostgreSQL server are assigned five-character error codes that follow the SQL standard's conventions for “SQLSTATE” codes.
Read more >Raw database access (Reference) - Prisma
Note: The Prisma Client query engine standardizes the return type for all ... If you use $queryRaw in conjunction with a PostgreSQL database,...
Read more >Performing raw SQL queries | Django documentation
raw() to perform raw queries and return model instances, or you can avoid the model layer entirely and execute custom SQL directly. Explore...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey @floriantz,
Could you try casting every single uuids as follow?
Let us know whether that fixes your issue.
I had tried something similar, yet a bit different. It works indeed with my repro case ✅ . Though it would be super helpful to update
Prisma.join()
to accept a type casting argument as proposed by @emmanuelpineda.I understand your choice of explicit types (actually I’m quite in favour of it), but the UX suffers a bit at the moment imho.