porsager / porsager/postgres

Unable to insert values of type `bigint[]`

Open
#837 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
8.7k
Forks
374
Avg merge
11d 16h
Merged PRs (30d)
1

Description

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!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the bigint[] INSERT reproduction shown in the issue with postgres.js and PostgreSQL. Trace how the sql({bigs: [...]}) parameter is encoded and compared with the string[] case; done means the bigint[] value is accepted as int8[] and the final assertion passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs, postgresql
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.