PostGreSQL - bind variables and date addition
- by azp74
I need to update some timestamp columns in a table in a PostGres (8.3) database.
My query (simplified) look like this:
update table1 set dateA = dateA + interval '10 hours' where id = 1234;
This is part of a script and there's a lot to update so my preference is to use bind variables, rather than to have to build the query string each time. This means my query becomes:
update table1 set dateA = dateA + interval '? hours' where id = ?;
When I do this, the complaint is that I've supplied 2 bind variables when only one is required.
If I try to put the ? outside the quote marks:
update table1 set dateA = dateA + interval ? ' hours' where id = ?;
I get:
... syntax error at or near "' hours'"
It looks as though the query has been interpreted as
... dateA = dateA + interval '10' ' hours' ...
I can't find anything in the documentation to help ... any suggestions?
Thanks