Nexy7574
Nexy7574

Reputation: 624

How do I pass an array to a postgresql where query?

I've got a rather simple query, I just need to check that a row's primary key is in an array of integers.

This is my current query:

SELECT * FROM entries WHERE id in [573240252177580032, 706271127542038608, 772980293929402389]

However, this yields the following error: 'syntax error near or at "["'

How can I do this?

Upvotes: 1

Views: 47

Answers (1)

S-Man
S-Man

Reputation: 23676

You can use the ANY function for that:

demo:db<>fiddle

SELECT * 
FROM entries 
WHERE id = ANY(ARRAY[573240252177580032, 706271127542038608, 772980293929402389])

Upvotes: 1

Related Questions