Skip site navigation (1) Skip section navigation (2)

Re: 'now' is sometimes not now - but current_timestamp is

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Guillaume Cottenceau <gc(at)mnc(dot)ch>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: 'now' is sometimes not now - but current_timestamp is
Date: 2006-10-13 14:14:23
Message-ID: 29408.1160748863@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-jdbc
Guillaume Cottenceau <gc(at)mnc(dot)ch> writes:
> I update a row's TIMESTAMP WITH TIME ZONE column value with:
>     ... SET <colname> = 'now'::TIMESTAMP WITH TIME ZONE ...

What you will have there is a timestamp-type constant with the value
that now() had at the time the statement was parsed.  If you re-use a
prepared statement then the value will be out of date.

> Initially, I was hesitating with CURRENT_TIMESTAMP, but in a
> table description, a column with a default value of 'now' or
> CURRENT_TIMESTAMP will both be printed "not null default
> ('now'::text)::timestamp(6) with time zone" so I assumed the
> correct way of writing it was 'now' and then to cast to a
> timestamp with/without time zone.

If you are going to copy the implementation of CURRENT_TIMESTAMP,
you should at least copy it accurately.  (Hint: the cast from
text to timestamp is not immutable.)  But why are you not just
using CURRENT_TIMESTAMP, rather than trying to outsmart the system?

			regards, tom lane

In response to

Responses

pgsql-jdbc by date

Next:From: Guillaume CottenceauDate: 2006-10-13 14:27:22
Subject: Re: 'now' is sometimes not now - but current_timestamp is
Previous:From: zhyu 86Date: 2006-10-13 14:09:36
Subject: Re: MBC user cannot connect to server

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group