brianc/node-pg-types

Parse array of BigInt

Closed this issue · 3 comments

s888 commented

Hi,
I have a column of type bigint[]
But in response, it is converted to an array of string.

How do I parse it?
This works when the column is of type bigint

import { types } from "pg"
types.setTypeParser(20, BigInt); 

Tried this but it gives an error.

import { Client, types } from "pg"
types.setTypeParser(1016, str => types.arrayParser(str,BigInt));

What error?

Must be that arrayParser(...) is no longer re-exported: 09ea625#diff-168726dbe96b3ce427e7fedce31bb0bcL3

Try something like this to use it directly from the postgres-array package:

const { types } = require('pg')
const pgArray = require('postgres-array')
types.setTypeParser(1016, text => pgArray.parse(text, BigInt))

Good catch, thanks!