dbTalk Databases Forums  

Timestamp Default value

comp.databases.postgresql.novice comp.databases.postgresql.novice


Discuss Timestamp Default value in the comp.databases.postgresql.novice forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Christopher A. Goodfellow
 
Posts: n/a

Default Timestamp Default value - 04-21-2004 , 10:58 AM






I created a table with column named orderdate and a default of Now() by the
following command:

CREATE TABLE "trans_test" (
"orderdate" timestamp without time zone DEFAULT timestamp 'now ( )' NOT
NULL,
etc...

The value inserted into this column when a record is inserted into the
table is the date and time the table was created. How do I get the value to
be the date and time the record is inserted short of modifying all my script
code and removing the default value?

This method did work in version 6.5. I am currently running 7.3.2.

Thank You,
Christopher A. Goodfellow
Director of Information Technology
Tealuxe, Inc.
Phone: 508 520 7887 ex:22
Fax: 508 528 8999
www.tealuxe.com
tea for all



---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match


Reply With Quote
  #2  
Old   
Tom Lane
 
Posts: n/a

Default Re: Timestamp Default value - 04-21-2004 , 02:03 PM






"Christopher A. Goodfellow" <cgoodfellow (AT) tealuxe (DOT) com> writes:
Quote:
I created a table with column named orderdate and a default of Now() by the
following command:

CREATE TABLE "trans_test" (
"orderdate" timestamp without time zone DEFAULT timestamp 'now ( )' NOT
NULL,
That should just be
... DEFAULT now() ...
or if you want to be SQL spec compliant
... DEFAULT LOCALTIMESTAMP ...

What you have is a timestamp literal that is parsed at the instant of
table creation. The parentheses are perhaps misleading you into
thinking that you have written a function call, but you haven't ---
the timestamp input converter is just ignoring them.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html



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.