vercel / vercel/storage

How do I pass an array into an SQL query?

Open
#906 0 comments 0 reactions 0 assignees View on GitHub

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

  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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.