porsager / porsager/postgres

WHERE IN throws `TypeError: str.replace is not a function`

Open
#701 7 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Queries with WHERE IN ${sql()} fails with error starting from version 3.4.0

await sql`
  select
    *
  from users
  where age in ${ sql([68, 75, 23]) }
`

Error:

TypeError: str.replace is not a function
    at escape (...\node_modules\postgres\cjs\src\types.js:217:20)
    at ...\node_modules\postgres\cjs\src\types.js:213:22
    at Array.map (<anonymous>)
    at escapeIdentifiers (...\node_modules\postgres\cjs\src\types.js:213:13)
    at Object.select [as fn] (...\node_modules\postgres\cjs\src\types.js:139:12)
    at Builder.build (...\node_modules\postgres\cjs\src\types.js:71:17)
    at stringifyValue (...\node_modules\postgres\cjs\src\types.js:109:38)
    at stringify (...\node_modules\postgres\cjs\src\types.js:100:16)
    at build (...\node_modules\postgres\cjs\src\connection.js:223:20)
    at Object.execute (...\node_modules\postgres\cjs\src\connection.js:167:7)
    at go (...\node_modules\postgres\cjs\src\index.js:341:14)
    at Query.handler (...\node_modules\postgres\cjs\src\index.js:330:14)
    at Query.handle (...\node_modules\postgres\cjs\src\query.js:140:65)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at new Query (...\node_modules\postgres\cjs\src\query.js:35:9)
    at Object.sql (...\node_modules\postgres\cjs\src\index.js:112:11)

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 in the types.js code shown in the stack trace, especially the escape and escapeIdentifiers paths, and compare behavior with the 3.4.0 change. Reproduce the supplied WHERE IN query using sql([68, 75, 23]); done means the query no longer throws TypeError and executes successfully.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.