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

Viewed 20

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?

1 Answers

You can use the ANY function for that:

demo:db<>fiddle

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