porsager / postgres

Postgres.js - The Fastest full featured PostgreSQL client for Node.js, Deno, Bun and CloudFlare
The Unlicense
7.04k stars 257 forks source link

Unable to insert values of type `bigint[]` #837

Open darkgnotic opened 3 months ago

darkgnotic commented 3 months ago

Using postgres({types: {bigint: postgres.BigInt}}) I am able to read both int8 and int8[] values as bigints.

I can also input values using string[] parameters for the latter. However, I get a failure when attempting to use a bigint[] as a parameter.

await sql`CREATE TABLE foo(big int8, bigs int8[])`;

await sql`INSERT INTO foo ${sql({big: 9007199254740993n})}`;
expect((await sql`SELECT * FROM foo`)[0]).toEqual({
  big: 9007199254740993n,
  bigs: null,
});

await sql`INSERT INTO foo ${sql({bigs: ['9007199254740993']})}`;
expect((await sql`SELECT * FROM foo`)[1]).toEqual({
  big: null,
  bigs: [9007199254740993n],
});

// Fails with:
//   PostgresError: column "bigs" is of type bigint[] but expression is of type bigint
await sql`INSERT INTO foo ${sql({bigs: [9007199254740994n]})}`;
expect((await sql`SELECT * FROM foo`)[2]).toEqual({
  big: null,
  bigs: [9007199254740994n],
});

Is there something more that I have to configure to be able to input bigint[] parameters?

Thank you for your help!