I am running the below SQL and it works fine:
const ids = book.map(({ id }) => id);
const myQuery = `
SELECT
row_to_json(s)
FROM (
SELECT
b.id, b.event_id, b.title, b.price, e.account_id
FROM
ticket_books b, event e
WHERE
b.event_id = e.id AND
b.id = ANY(ARRAY[${ids}])
) s
`;
const result = await server.pg.query(myQuery);
I would like to switch to prepared statements, so I rewrote the above as:
const myQuery = `
SELECT
row_to_json(s)
FROM (
SELECT
b.id, b.event_id, b.title, b.price, e.account_id
FROM
ticket_books b, event e
WHERE
b.event_id = e.id AND
b.id = ANY(ARRAY[$1])
) s
`;
const result = await server.pg.query(myQuery, [ids]);
The prepared statement version is failing with: error: operator does not exist: integer = text.
What is the problem?
ids? Is it an array of integers or strings?const ids = [1,2,3]does it work?number.