Re: BUG #1598: using default 'now', or now() or CURRENT_TIMESTAMP

From: Richard Huxton <dev(at)archonet(dot)com>
To: Nicolas HAHN <hahnn(at)x-itools(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #1598: using default 'now', or now() or CURRENT_TIMESTAMP
Date: 2005-04-15 15:13:10
Message-ID: 425FDA06.4060904@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Nicolas HAHN wrote:
> The following bug has been logged online:
>
> Bug reference: 1598
> Logged by: Nicolas HAHN
> Email address: hahnn(at)x-itools(dot)com
> PostgreSQL version: 7.4.7
> Operating system: Fedora Core 3
> Description: using default 'now', or now() or CURRENT_TIMESTAMP when
> creating table does not work as expected
> Details:

> **********************
> case 2: using default now(), which doesn't work as expected according the
> doc:
>
> BEGIN;
> CREATE TABLE test (date timestamp not null default now(), val varchar(64));
> INSERT INTO test (val) values ('test 1 at time T');
> ########### Here I wait 1 minute #############
> INSERT INTO test (val) values ('test 2 at time T+1 min');
> SELECT * from test;
> date | val
> ----------------------------+------------------------
> 2005-04-15 13:50:53.419981 | test 1 at time T
> 2005-04-15 13:50:53.419981 | test 2 at time T+1 min
> (2 rows)
> ROLLBACK;

This particular case will give the same time because it is all in the
same transaction. CURRENT_TIMESTAMP/now() are "frozen" at start of
transaction, so you can store several timestamps with the same value.

Try commit/begin where you wait for one minute - that should do it.

Alternatively, look at timeofday() instead.

--
Richard Huxton
Archonet Ltd

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2005-04-15 16:41:42 Re: BUG #1597: pg_dump --verbose ignores --disable-triggers
Previous Message Stephan Szabo 2005-04-15 14:56:43 Re: BUG #1598: using default 'now', or now() or CURRENT_TIMESTAMP