Skip to content

[BUG]: Do not know how to serialize a BigInt #899

@AntonOfTheWoods

Description

@AntonOfTheWoods

Describe the bug
When arrays are passed as parameters to the query function, the "dumb" version of the JSON.stringify is used, and this fails for BigInts.

To Reproduce - include code sample(s)

  const pg = await PGlite.create();
  const myint = [{ id: 1 }, { id: 2 }];
  const mybigint = [{ id: 1n }, { id: 2n }];
  await pg.exec(`CREATE TABLE IF NOT EXISTS "myint" ("id" int NOT NULL);`);
  await pg.exec(`CREATE TABLE IF NOT EXISTS "mybigint" ("id" bigint NOT NULL);`);
  await pg.query(`INSERT INTO myint (id) SELECT x.* from json_to_recordset($1) as x(id int); `, [myint]);
  console.log("got", await pg.query("SELECT * FROM myint"));
  // the following line fails
  await pg.query(`INSERT INTO mybigint (id) SELECT x.* from json_to_recordset($1) as x(id bigint); `, [mybigint]);
  console.log("got", await pg.query("SELECT * FROM mybigint"));

Logs

got {
  rows: [ { id: 1 }, { id: 2 } ],
  fields: [ { name: "id", dataTypeID: 23 } ],
  affectedRows: 0
}
error: Uncaught (in promise) TypeError: Do not know how to serialize a BigInt
  return Array.isArray(r)
^
    at stringify (<anonymous>)
    at serialize (file:///home/anton/.cache/deno/npm/registry.npmjs.org/@electric-sql/pglite/0.3.15/dist/chunk-3WWIVTCY.js:249:1)
    at file:///home/anton/.cache/deno/npm/registry.npmjs.org/@electric-sql/pglite/0.3.15/dist/chunk-F2DQ4FIK.js:530:3
    at Array.map (<anonymous>)
    at file:///home/anton/.cache/deno/npm/registry.npmjs.org/@electric-sql/pglite/0.3.15/dist/chunk-F2DQ4FIK.js:530:3

Details

  • PGlite version: 0.3.15

Additional context
This also affects the json initial insert mode for pglite-sync

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions