$queryRaw fails when passing bigint as parameter
See original GitHub issueBug description
My Postgres database uses BigInt for identifiers, but $queryRaw
fails loudly when I try to pass a bigint
as a parameter:
Raw query failed. Code: `08P01`. Message: `db error: ERROR: insufficient data left in message`
How to reproduce
From the Node REPL:
await prisma.$queryRaw`SELECT ${1n}::bigint;`
Uncaught PrismaClientKnownRequestError2 [PrismaClientKnownRequestError]:
Invalid `prisma.queryRaw()` invocation:
Raw query failed. Code: `08P01`. Message: `db error: ERROR: insufficient data left in message`
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at cb (/app/prisma-client/runtime/index.js:33896:17) {
code: 'P2010',
clientVersion: '2.26.0',
meta: {
code: '08P01',
message: 'db error: ERROR: insufficient data left in message'
}
}
Passing in a number does not fail, but reproduces https://github.com/prisma/prisma/issues/7395 (the resulting value is not a bigint
):
await prisma.$queryRaw`SELECT ${1}::bigint;`
[ { int8: 1 } ]
Expected behavior
Expected 1n
to be serialized as a Postgres bigint
; expected query not to fail.
Prisma information
This is reproducible without a schema
Environment & setup
- OS: Alpine Linux 3.13
- Database: Postgres 13.3
- Node.js version: 14.17.1
- Prisma version: 2.26.0
Prisma Version
npm exec prisma -v
6.14.11
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Bytea parameter in a prisma raw query - sql - Stack Overflow
I am using Typescript + Prisma + Postgres and I am running into problems with passing bytea/Buffer parameters to raw queries.
Read more >Raw database access (Reference) - Prisma
For relational databases, Prisma Client exposes four methods that allow you to send raw queries. You can use: $queryRaw to return actual records...
Read more >Building a SQL Query from Variables with prisma.$queryRaw
queryRaw, I was able to write a basic query that returned the data I needed. ... Produces a Prisma Error const sortingClause =...
Read more >How to pass parameter for bigint field with multiple values ...
Excecuting query I am getting an error as cannot cast varchar to bigint. How to solve it. Please Help me.. Thanks & Regards,...
Read more >prisma/prisma 3.14.0 on GitHub - NewReleases.io
queryRaw `SELECT bigint, bytes, decimal, date FROM "Table";` console.log(res) ... Passing the types as query parameters now works:.
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,
This issue was fixed by https://github.com/prisma/prisma-engines/pull/2847 and will be available in the next release.
Thanks for reporting 🙏
Confirmed this works in 3.14.0. You don’t need to specify
::bigint
, justWHERE id=${bigIntHere}
works as-is 🎉