Nested arrays aren't expanded properly in 3.4.3
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 8.7k
- Forks
- 374
- Avg merge
- 11d 16h
- Merged PRs (30d)
- 1
Description
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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the nested-array query from lib/build/testanotheridea.js, then inspect postgres/src/types.js around escapeIdentifiers (lines 213-217), Builder.build, and stringifyValue. Compare behavior with version 3.3.5 and 3.4.3; done means the query no longer raises TypeError: str.replace is not a function for the shown input.
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
- 38/100