Re: [GENERAL] Date & Time - Mailing list pgsql-general

From
Subject Re: [GENERAL] Date & Time
Date
Msg-id Pine.LNX.4.10.9912020943400.19647-100000@picasso.realtyideas.com
Whole thread Raw
In response to Re: [GENERAL] Date & Time  (Bruce Momjian <pgman@candle.pha.pa.us>)
List pgsql-general
Here is the test. I did not put it in mail because pine did not like
cut/paste. now I find a way to do it. It looks good!
the conclusion: current_timestamp is "current" -- it should be,
   the looks closer than now/now()  :-)

###############################################################
test3=> drop table account;

DROP
test3=> CREATE TABLE account (

        test3->                  act char(1) default 'Y',

        test3->                  createdfunc DATETIME DEFAULT now(),

        test3->                  createdcons DATETIME DEFAULT 'now',

        test3->                  created2cons DATETIME DEFAULT 'current_timestamp',

        test3->                  createdcurr DATETIME DEFAULT 'current'

        test3->                  );

CREATE
test3=>

test3=>

test3=> insert into account values('y');

INSERT 283346 1
test3=> insert into account values('1');
INSERT 283347 1
test3=> insert into account (createdcons) values(now());

INSERT 283348 1
test3=> insert into account (createdcons) values(now);

ERROR:  Attribute now not found
test3=> insert into account (createdcons) values('now');

INSERT 283349 1
test3=> insert into account (createdcons) values(current);

ERROR:  Attribute current not found
test3=> insert into account (createdcons) values('current');

INSERT 283350 1
test3=> insert into account (createdcons) values(current_timestamp);

INSERT 283351 1
test3=> insert into account (createdcons) values('current_timestamp');

INSERT 283352 1
test3=>
test3=> insert into account (createdcons) values(current_timestamp());

ERROR:  parser: parse error at or near ")"
test3=> insert into account (createdcons) values(current_timestamp(now));

ERROR:  parser: parse error at or near "now"
test3=> insert into account (createdcons) values(current_timestamp('now'));

ERROR:  parser: parse error at or near "'"
test3=> insert into account (createdcons) values(now(current_timestamp));

ERROR:  No such function 'now' with the specified attributes
test3=>

test3=> select * from account;

act|createdfunc                 |createdcons                 |created2cons|createdcurr
---+----------------------------+----------------------------+------------+-----------
y  |Thu Dec 02 08:41:34 1999 CST|Thu Dec 02 08:41:33 1999 CST|current     |current
1  |Thu Dec 02 08:41:34 1999 CST|Thu Dec 02 08:41:33 1999 CST|current     |current
Y  |Thu Dec 02 08:41:34 1999 CST|Thu Dec 02 08:41:34 1999 CST|current     |current
Y  |Thu Dec 02 08:41:34 1999 CST|Thu Dec 02 08:41:34 1999 CST|current     |current
Y  |Thu Dec 02 08:41:34 1999 CST|current                     |current     |current
Y  |Thu Dec 02 08:41:34 1999 CST|Thu Dec 02 08:41:34 1999 CST|current     |current
Y  |Thu Dec 02 08:41:34 1999 CST|current                     |current     |current
(7 rows)

test3=> select * from account where createdcons = 'now';

act|createdfunc                 |createdcons                 |created2cons|createdcurr
---+----------------------------+----------------------------+------------+-----------
Y  |Thu Dec 02 08:41:34 1999 CST|Thu Dec 02 08:41:34 1999 CST|current     |current
Y  |Thu Dec 02 08:41:34 1999 CST|Thu Dec 02 08:41:34 1999 CST|current     |current
Y  |Thu Dec 02 08:41:34 1999 CST|current                     |current     |current
Y  |Thu Dec 02 08:41:34 1999 CST|Thu Dec 02 08:41:34 1999 CST|current     |current
Y  |Thu Dec 02 08:41:34 1999 CST|current                     |current     |current
(5 rows)

test3=> select * from account where createdcons = now();

act|createdfunc                 |createdcons                 |created2cons|createdcurr
---+----------------------------+----------------------------+------------+-----------
Y  |Thu Dec 02 08:41:34 1999 CST|Thu Dec 02 08:41:34 1999 CST|current     |current
Y  |Thu Dec 02 08:41:34 1999 CST|Thu Dec 02 08:41:34 1999 CST|current     |current
Y  |Thu Dec 02 08:41:34 1999 CST|current                     |current     |current
Y  |Thu Dec 02 08:41:34 1999 CST|Thu Dec 02 08:41:34 1999 CST|current     |current
Y  |Thu Dec 02 08:41:34 1999 CST|current                     |current     |current
(5 rows)

test3=> select * from account where createdcons = 'current';
act|createdfunc                 |createdcons                 |created2cons|createdcurr
---+----------------------------+----------------------------+------------+-----------
Y  |Thu Dec 02 08:41:34 1999 CST|Thu Dec 02 08:41:34 1999 CST|current     |current
Y  |Thu Dec 02 08:41:34 1999 CST|Thu Dec 02 08:41:34 1999 CST|current     |current
Y  |Thu Dec 02 08:41:34 1999 CST|current                     |current     |current
Y  |Thu Dec 02 08:41:34 1999 CST|Thu Dec 02 08:41:34 1999 CST|current     |current
Y  |Thu Dec 02 08:41:34 1999 CST|current                     |current     |current
(5 rows)

    test3=> select * from account where createdcons = 'current_timestamp';

    act|createdfunc                 |createdcons|created2cons|createdcurr
    ---+----------------------------+-----------+------------+-----------
    Y  |Thu Dec 02 08:41:34 1999 CST|current    |current     |current
    Y  |Thu Dec 02 08:41:34 1999 CST|current    |current     |current
    (2 rows)

    test3=> select * from account where createdcons = current_timestamp();

ERROR:  parser: parse error at or near ")"
test3=> select * from account where createdcons = current_timestamp('now');

ERROR:  parser: parse error at or near "'"
test3=> select * from account where createdcons = 'current_timestamp('now')';

ERROR:  parser: parse error at or near "now"





##############################################################
On Wed, 1 Dec 1999, Bruce Momjian wrote:

> > Ed Loehr ha scritto:
> >
> > > Just curious:  anyone have any comment on any practical differences between now() and CURRENT_TIMESTAMP, which
seemsto work 
> > > the same?
> > >
> >
> > I think it is the same function, both of them return the current date and time.
> >
> > now() should be the internal postgreSQL function.
> > and CURRENT_TIMESTAMP is the exact SQL-92 syntax
>
> I am changing my book to use CURRENT_TIMESTAMP rather than now().
>
> --
>   Bruce Momjian                        |  http://www.op.net/~candle
>   maillist@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
>
> ************
>


pgsql-general by date:

Previous
From:
Date:
Subject: Re: [GENERAL] Except operation
Next
From: Mark Jewiss
Date:
Subject: Upper/lower case passwords