Heya, how would one go about passing parameters to a query with IN?
For example:
SELECT *
FROM people
WHERE name in ($1)
I've tried to use:
pg.query(query, [['drake', 'zoey']], cb)
But I don't get results back when both drake and zoey are in the table.
However the following does seem to work:
pg.query(query.replace(/\$1/, ['drake', 'zoey'].map(v => `'${v}'`).join(','), cb)
You can use = ANY instead:
SELECT *
FROM people
WHERE name = ANY ($1)
Duplicate of #1452
However the following does seem to work:
pg.query(query.replace(/\$1/, ['drake', 'zoey'].map(v => `'${v}'`).join(','), cb)
(and, to be clear, definitely do not do this. It鈥檚 an SQL injection vulnerability.)
<3 thank you
Most helpful comment
You can use
= ANYinstead: