now() does not change within a transaction
now() does not change within a transaction
От:
Christoph Haller <ch@rodos.fzk.de>
Дата:
Hi pgsql-sql list, I did some testing around tables using a column timestamp with time zone not null default now(). I have noticed a valuable feature: As long as being inside a transaction initiated by begin; the return value of the now() function does not change. Is this intended - as written in the documentation? Can I rely on it, so future releases of PostgreSQL will act the same. Regards, Christoph
Re: now() does not change within a transaction
От:
Karel Zak <zakkr@zf.jcu.cz>
Дата:
On Thu, Apr 18, 2002 at 02:04:35PM +0000, Christoph Haller wrote:
> Hi pgsql-sql list,
> I did some testing around tables using a column
> timestamp with time zone not null default now().
> I have noticed a valuable feature:
> As long as being inside a transaction initiated by
> begin;
> the return value of the now() function does not change.
> Is this intended - as written in the documentation?
Sure. See (for example):
http://docs.linux.cz/PostgreSQL/functions-datetime.html#FUNCTIONS-DATETIME-CURRENT
It is quite important to realize that CURRENT_TIMESTAMP and related functions all return the time as of the start of the current transaction; their values do not increment while a transaction is running. But timeofday() returns the actual current time.
test=# select timeofday()::timestamp; timeofday
-------------------------------2002-04-18 14:39:36.459162+02
Karel
-- Karel Zak http://home.zf.jcu.cz/~zakkr/C, PostgreSQL, PHP, WWW, http://docs.linux.cz, http://mape.jcu.cz
Re: now() does not change within a transaction
От:
Bruce Momjian <pgman@candle.pha.pa.us>
Дата:
Christoph Haller wrote: > Hi pgsql-sql list, > I did some testing around tables using a column > timestamp with time zone not null default now(). > I have noticed a valuable feature: > As long as being inside a transaction initiated by > begin; > the return value of the now() function does not change. > Is this intended - as written in the documentation? > Can I rely on it, so future releases of PostgreSQL > will act the same. Yes, this is intended and will not change. -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 853-3000 + If your life is a hard drive, | 830 Blythe Avenue + Christ can be your backup. | Drexel Hill, Pennsylvania 19026