porsager / postgres

Postgres.js - The Fastest full featured PostgreSQL client for Node.js, Deno, Bun and CloudFlare

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Nested arrays aren't expanded properly in 3.4.3

baileywickham opened this issue · comments

Using nested arrays in a where statement causes an error in

import postgres from 'postgres';

const sql = postgres('postgres:///', {
                prepare: false,
});

const values = [
	[]
];

const res = await sql`SELECT a, b FROM fner WHERE (a, b) IN (${sql(values)})`;

console.log(res);

This is the output from running this code where the first line is a console.log from sql on line 112 of index.js

[ 'SELECT a, b FROM fner WHERE (a, b) IN (', ')' ] [ Builder { first: [ [] ], rest: [] } ]
node:internal/process/esm_loader:40
      internalBinding('errors').triggerUncaughtException(
                                ^

TypeError: str.replace is not a function
    at escape (file:///home/admin/proto-0.14.0-747-g66d563cf/node_modules/.pnpm/postgres@3.4.3/node_modules/postgres/src/types.js:217:20)
    at file:///home/admin/proto-0.14.0-747-g66d563cf/node_modules/.pnpm/postgres@3.4.3/node_modules/postgres/src/types.js:213:22
    at Array.map (<anonymous>)
    at escapeIdentifiers (file:///home/admin/proto-0.14.0-747-g66d563cf/node_modules/.pnpm/postgres@3.4.3/node_modules/postgres/src/types.js:213:13)
    at Object.select [as fn] (file:///home/admin/proto-0.14.0-747-g66d563cf/node_modules/.pnpm/postgres@3.4.3/node_modules/postgres/src/types.js:139:12)
    at Builder.build (file:///home/admin/proto-0.14.0-747-g66d563cf/node_modules/.pnpm/postgres@3.4.3/node_modules/postgres/src/types.js:71:17)
    at stringifyValue (file:///home/admin/proto-0.14.0-747-g66d563cf/node_modules/.pnpm/postgres@3.4.3/node_modules/postgres/src/types.js:109:38)
    at stringify (file:///home/admin/proto-0.14.0-747-g66d563cf/node_modules/.pnpm/postgres@3.4.3/node_modules/postgres/src/types.js:100:16)
    at build (file:///home/admin/proto-0.14.0-747-g66d563cf/node_modules/.pnpm/postgres@3.4.3/node_modules/postgres/src/connection.js:223:20)
    at execute (file:///home/admin/proto-0.14.0-747-g66d563cf/node_modules/.pnpm/postgres@3.4.3/node_modules/postgres/src/connection.js:167:7)
    at cachedError (file:///home/admin/proto-0.14.0-747-g66d563cf/node_modules/.pnpm/postgres@3.4.3/node_modules/postgres/src/query.js:170:23)
    at new Query (file:///home/admin/proto-0.14.0-747-g66d563cf/node_modules/.pnpm/postgres@3.4.3/node_modules/postgres/src/query.js:36:24)
    at sql (file:///home/admin/proto-0.14.0-747-g66d563cf/node_modules/.pnpm/postgres@3.4.3/node_modules/postgres/src/index.js:113:11)
    at file:///home/admin/proto-0.14.0-747-g66d563cf/lib/build/testanotheridea.js:11:22
    at cachedError (file:///home/admin/proto-0.14.0-747-g66d563cf/node_modules/.pnpm/postgres@3.4.3/node_modules/postgres/src/query.js:170:23)
    at new Query (file:///home/admin/proto-0.14.0-747-g66d563cf/node_modules/.pnpm/postgres@3.4.3/node_modules/postgres/src/query.js:36:24)
    at sql (file:///home/admin/proto-0.14.0-747-g66d563cf/node_modules/.pnpm/postgres@3.4.3/node_modules/postgres/src/index.js:113:11)

This was working on version 3.3.5 and when we upgraded to 3.4.3 this error started showing up for us. Let me know how I can help.

Seems like the same issue as #701. There's a workaround there you might find useful.