logo       
Google Custom Search
    AddThis Social Bookmark Button
-->

Re: How do i execute "update table set t=interval '1 day': msg#00130

Subject: Re: How do i execute "update table set t=interval '1 day'
On Jun 29, 2006, at 2:06 PM, Mario Romero wrote:

> I need to execute an update similar to:
> update table set timestamp_field=localtimestamp + interval '1 day'
> where 'localtimestamp + interval '1 day' is a variable value, it can 
> be Null
> too.
>
> I would like to use the tuple method to pass the value
>    cur.execute("update table set timestamp_field=%s", (XXX,))
> instead of
>    cur.execute("update table set timestamp_field=" + interval)
> because the real query is much longer and includes other values I 
> would like
> to include in the tuple and breaking the string to concatenate the 
> interval
> makes it less legible.
>
> Can I put something in the XXX that works?

Mario,
You might find it easier to construct the query if you always express 
the interval in seconds. That way you can just pass an integer (or 
NULL) --

update table set timestamp_field= (%s * interval '1 second')

Hope this helps
Philip


<Prev in Thread] Current Thread [Next in Thread>