Home > database >  Pass array as parameter to return all rows matching elements
Pass array as parameter to return all rows matching elements

Time:12-22

I am using Postgres for my Javascript project and I have an array of id's. Is there a way to return all the rows and their corresponding data using each id in the array.

Array of Id's

I want to return all the rows that has the id that is in the array.

CodePudding user response:

One of various ways: pass an array literal to the = ANY construct:

SELECT * FROM tbl WHERE id = ANY ('{46995, 54262, 73166}');

See:

  • Related