I have a query like this
UPDATE
my_table
SET
expire_after = now() + INTERVAL $1
RETURNING *
and try to parameterize the query with
pg.query(my_query, ['30 seconds'])
It doesn't work and throws an error :-(
ERROR: syntax error at or near "$1" at character xxx
INTERVAL '…' is an interval literal; you would use $1::interval to interpret a parameter as an interval. (Passing [30] and adding $1 * INTERVAL '1 second' might also be appropriate.)
The $1::interval doesn't work for me but the $1 * INTERVAL '1 second' works. Thanks for the tips.
Most helpful comment
INTERVAL '…'is an interval literal; you would use$1::intervalto interpret a parameter as an interval. (Passing[30]and adding$1 * INTERVAL '1 second'might also be appropriate.)