SQL noob trying to return db results if a table value is found in an array. I'm using Node JS and Postgres.
So far, I can figure out how to return the result for a single item:
SELECT * FROM table WHERE position(value in 'someval1')>0
// returns [{ id: 1, value: 'val1' }]
I don't know how to replace the single item above ('someval1') with an array.
EXAMPLE
Given the following table:
id | value |
---|---|
1 | val1 |
2 | val2 |
3 | val3 |
and the array:
['foo', 'someval1', 'anotherval2', 'bar']
how might I check that table "value" exists within each array item to return:
[
{ id: 1, value: 'val1' },
{ id: 2, value: 'val2' }
]