N
Neon6mo ago
correct-apricot

Yep, but it looks like that's not the

Yep, but it looks like that's not the right OID for _int8:
const { neon, types } = await import('@neondatabase/serverless');
const sql = neon('postgresql://...');

types.setTypeParser(types.builtins.INT8, int8 => `int8:${int8}`);
console.log(await sql`SELECT '1'::int8`);

const [{ oid: int8oid }] = await sql`SELECT oid FROM pg_type WHERE typname = '_int8'`;
console.log({ int8oid });

types.setTypeParser(int8oid, int8 => `int8[]:${int8}`);
console.log(await sql`SELECT '{1, 2, 3}'::int8[]`);
const { neon, types } = await import('@neondatabase/serverless');
const sql = neon('postgresql://...');

types.setTypeParser(types.builtins.INT8, int8 => `int8:${int8}`);
console.log(await sql`SELECT '1'::int8`);

const [{ oid: int8oid }] = await sql`SELECT oid FROM pg_type WHERE typname = '_int8'`;
console.log({ int8oid });

types.setTypeParser(int8oid, int8 => `int8[]:${int8}`);
console.log(await sql`SELECT '{1, 2, 3}'::int8[]`);
Which produces:
[ { int8: 'int8:1' } ]
{ int8oid: 1016 }
[ { int8: 'int8[]:{1,2,3}' } ]
[ { int8: 'int8:1' } ]
{ int8oid: 1016 }
[ { int8: 'int8[]:{1,2,3}' } ]
2 Replies
reduced-jade
reduced-jade6mo ago
Thanks! Not sure where I read that the array type would be the base type + 1000 ironically the gpt told me it was 1016 but I overrode it thinking i was making a big brain move

Did you find this page helpful?