Skip to content

BigInt errors inside prepared statements #2395

Closed
@vitaly-t

Description

@vitaly-t

Why use of BigInt in Prepared Statements throws an error inside this library's formatter?

const a = {d: 1n};
await pool.query({text: 'SELECT $1 as value', values: [a]});

throws library-level error (not server-level):

(node:65560) UnhandledPromiseRejectionWarning: TypeError: Do not know how to serialize a BigInt
    at JSON.stringify (<anonymous>)
    at prepareObject (/Users/~/Documents/Git/Personal/pg-queue/node_modules/pg/lib/utils.js:80:15)
    at prepareValue (/Users/~/Documents/Git/Personal/pg-queue/node_modules/pg/lib/utils.js:65:12)
    at prepareValueWrapper (/Users/~/Documents/Git/Personal/pg-queue/node_modules/pg/lib/utils.js:181:12)
    at Array.map (<anonymous>)
    at Query.prepare (/Users/~/Documents/Git/Personal/pg-queue/node_modules/pg/lib/query.js:202:35)
    at Query.submit (/Users/~/Documents/Git/Personal/pg-queue/node_modules/pg/lib/query.js:155:12)
    at Client._pulseQueryQueue (/Users/~/Documents/Git/Personal/pg-queue/node_modules/pg/lib/client.js:472:45)
    at Client.query (/Users/~/Documents/Git/Personal/pg-queue/node_modules/pg/lib/client.js:567:10)

Note that the error is thrown while preparing the query for execution, and not on the returned result.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions