Re: I was spoiled by the MySQL timestamp field

From: will trillich <will(at)serensoft(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: I was spoiled by the MySQL timestamp field
Date: 2003-01-24 19:36:13
Message-ID: 20030124193611.GA21258@mail.serensoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Jan 24, 2003 at 10:55:26AM -0500, Tom Lane wrote:
> Dennis Gearon <gearond(at)cvc(dot)net> writes:
> > What's the difference between 'now()' and 'current_timestamp' ?
>
> None AFAIK. now() is historical Postgres usage, CURRENT_TIMESTAMP is
> the SQL-spec-mandated spelling of the same functionality.
>
> CURRENT_TIMESTAMP with an argument does something a bit different,
> though.
>
> http://www.ca.postgresql.org/users-lounge/docs/7.3/postgres/functions-datetime.html#FUNCTIONS-DATETIME-CURRENT

the one caveat is outlined at the bottom of that very page:

All the date/time data types also accept the special literal
value now to specify the current date and time. Thus, the
following three all return the same result:

SELECT CURRENT_TIMESTAMP;
SELECT now();
SELECT TIMESTAMP 'now';

Note: You do not want to use the third form when specifying
a DEFAULT clause while creating a table. The system will
convert now to a timestamp as soon as the constant is
parsed, so that when the default value is needed, the ##TIME
OF THE TABLE CREATION## would be used! The first two forms
will not be evaluated until the default value is used,
because they are function calls. Thus they will give the
desired behavior of defaulting to the time of row insertion.

[emphasis mine]

so careful using "now" when you mean to use "now()".
or better yet, "current_timestamp" for consistency.

--
There are 10 kinds of people:
ones that get binary, and ones that don't.

will(at)serensoft(dot)com
http://sourceforge.net/projects/newbiedoc -- we need your brain!
http://www.dontUthink.com/ -- your brain needs us!

Looking for a firewall? Do you think smoothwall sucks? You're
probably right... Try the folks at http://clarkconnect.org/ !

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Greg Stark 2003-01-24 19:41:37 Re: More PHP DB abstraction layer stuff
Previous Message Nigel J. Andrews 2003-01-24 19:15:52 Re: More PHP DB abstraction layer stuff