dbTalk Databases Forums  

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

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss Re: [BUGS] BUG #1598: using default 'now', or now() or CURRENT_TIMESTAMP in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Stephan Szabo
 
Posts: n/a

Default Re: [BUGS] BUG #1598: using default 'now', or now() or CURRENT_TIMESTAMP - 04-15-2005 , 10:01 AM







On Fri, 15 Apr 2005, Nicolas HAHN wrote:

Quote:
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:

I read the doc and saw that, to avoid the problem of using a default 'now'
when creating the table which makes each record to have the timestamp of
when the table has been created, default now() or default CURRENT_TIMESTAMP
must be used instead. But using this is exactly the same as using 'now': I
still get the same timestamp for each record I insert in the table.
now() is transaction start time and as such isn't going to vary within one
transaction, no matter how long you wait. The issue is what happens when
you commit the first transaction and start another and insert and whether
you get the transaction start time of the first transaction or the second.

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo (AT) postgresql (DOT) org)


Reply With Quote
  #2  
Old   
Richard Huxton
 
Posts: n/a

Default Re: [BUGS] BUG #1598: using default 'now', or now() or CURRENT_TIMESTAMP - 04-15-2005 , 10:17 AM






Nicolas HAHN wrote:
Quote:
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

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo (AT) postgresql (DOT) org)


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.