How do I pass an array into an SQL query?
Open
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 595
- Forks
- 101
- Avg merge
- 2h 24m
- Merged PRs (30d)
- 1
Description
I'm trying to pass an array of numbers into an UPDATE query. I tried this:
const ids = [0,1,2];
await sql`
UPDATE scheduled_notifications
SET last_sent_at = NOW()
WHERE id = ANY(${ids}::bigint[])
`;
but TypeScript doesn't like that "ids" is a "number[]" and not a "Primitive."
What should I do instead?
Please & thank you!
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
Start with the tagged SQL template usage shown in the issue and the TypeScript error about number[] versus Primitive. Check the repository's documented query-parameter handling for arrays and verify that the UPDATE can safely target the listed ids; done means the query type-checks and updates the intended rows.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- sql, typescript
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100