PostGreSQL - bind variables and date addition

Posted by azp74 on Stack Overflow See other posts from Stack Overflow or by azp74
Published on 2010-05-11T06:01:55Z Indexed on 2010/05/11 6:04 UTC
Read the original article Hit count: 252

Filed under:

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

© Stack Overflow or respective owner

Related posts about postgresql