Re: [HACKERS] create table and default 'now' problem ?

From: José Soares <jose(at)sferacarta(dot)com>
To: Oleg Bartunov <oleg(at)sai(dot)msu(dot)su>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [HACKERS] create table and default 'now' problem ?
Date: 1980-01-02 13:38:36
Message-ID: 12D0B75C.241E4474@sferacarta.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

You can use DEFAULT CURRENT_TIMESTAMP as in:

prova=> create table test ( a datetime default current_timestamp, b int4);

prova=> insert into test (b) values (1);
INSERT 941004 1

prova=> insert into test (b) values (1);
INSERT 941005 1
prova=> select * from test1;
a |b
---------------------------+-
21/09/1999 16:26:45.00 CEST|1
21/09/1999 16:26:50.00 CEST|1
(2 rows)

José

Oleg Bartunov ha scritto:

> Hi,
>
> how I could create table with datetime field default to 'now'::text in
> a way Jan did in his shoes rule example ?
>
> If I do:
> test=> create table test ( a datetime default 'now', b int4);
> CREATE
> test=> insert into test (b) values (1);
> INSERT 1677899 1
> test=> insert into test (b) values (2);
> INSERT 1677900 1
> test=> select * from test;
> a |b
> ----------------------------+-
> Tue 21 Sep 01:48:27 1999 MSD|1
> Tue 21 Sep 01:48:27 1999 MSD|2
> (2 rows)
>
> I always get datetime of the moment I created the table, but I'd like
> to have datetime of moment I insert.
>
> Regards,
>
> Oleg
>
> _____________________________________________________________
> Oleg Bartunov, sci.researcher, hostmaster of AstroNet,
> Sternberg Astronomical Institute, Moscow University (Russia)
> Internet: oleg(at)sai(dot)msu(dot)su, http://www.sai.msu.su/~megera/
> phone: +007(095)939-16-83, +007(095)939-23-83
>
> ************

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message José Soares 1980-01-04 14:49:55 Re: [HACKERS] All things equal, we are still alot slower then MySQL?
Previous Message ozsevim 0102-11-07 22:44:25 c/sql