Node-postgres: "INTERVAL $1" is not parameterized

Created on 15 Mar 2018  Â·  2Comments  Â·  Source: brianc/node-postgres

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

Most helpful comment

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.)

All 2 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chrisjensen picture chrisjensen  Â·  4Comments

gajus picture gajus  Â·  4Comments

KeynesYouDigIt picture KeynesYouDigIt  Â·  3Comments

gpanainte picture gpanainte  Â·  3Comments

spollack picture spollack  Â·  4Comments