Skip to content

How do I pass an array into an SQL query? #906

@moonman239

Description

@moonman239

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions