question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

$queryRaw fails when passing bigint as parameter

See original GitHub issue

Bug 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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
Weakkycommented, May 6, 2022

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 🙏

1reaction
chrisvarietycommented, May 11, 2022

Confirmed this works in 3.14.0. You don’t need to specify ::bigint, just WHERE id=${bigIntHere} works as-is 🎉

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found