From ty@koi.tsukebe.net Tue Apr 18 10:37:25 2000 Received: from koi.tsukebe.net (root@h-207-228-97-66.gen.cadvision.com [207.228.97.66]) by hub.org (8.9.3/8.9.3) with ESMTP id GAA06109 for ; Tue, 18 Apr 2000 06:37:25 -0400 (EDT) (envelope-from ty@koi.tsukebe.net) Received: from ip74.tsukebe.net ([207.228.97.74] helo=indus) by koi.tsukebe.net with smtp (Exim 3.03 #3) id 12hVT1-0000w6-00 for pgsql-admin@postgresql.org; Tue, 18 Apr 2000 10:42:51 +0000 Message-ID: <000e01bfa922$03466330$a20efea9@indus> From: "ty" To: Subject: DEFAULT now() ? Date: Tue, 18 Apr 2000 10:36:53 -0000 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_000B_01BFA922.0335C160" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.00.2919.6700 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700 X-Archive-Number: 200004/67 This is a multi-part message in MIME format. ------=_NextPart_000_000B_01BFA922.0335C160 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable May someone please show me the necessary code snippets that would allow the= value of a column to take the current time ( ala now() ) by default on INS= ERT? Indicative example: CREATE TABLE foo ( a INTEGER NOT NULL DEFAULT 0, b DATETIME NOT NULL DEFAULT now() ); INSERT INTO foo (a) VALUES (123); What happens here? Well, a row is inserted into table ``foo'' where ``a'' h= as the value 123 and b holds the date & time of when the create DDL stateme= nt was executed. I'm wondering how to get b to have the value of the time w= henever any arbitrary insert statement is executed... Ty ------=_NextPart_000_000B_01BFA922.0335C160 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
May someone please show me the necessary c= ode=20 snippets that would allow the value of a column to take the current ti= me (=20 ala now() ) by default on INSERT?
 
Indicative example:
 
CREATE TABLE foo (
    a INTEGER NOT NULL DEFA= ULT=20 0,
    b DATETIME NOT NULL DEF= AULT=20 now()
);
 
INSERT INTO foo (a) VALUES (123);
 
What happens here? Well, a row is inserted= into=20 table ``foo'' where ``a'' has the value 123 and b holds the date &= time=20 of when the create DDL statement was executed. I'm wondering how to get b t= o=20 have the value of the time whenever any arbitrary insert statement is=20 executed...
 
Ty
 
------=_NextPart_000_000B_01BFA922.0335C160-- From brita@umich.edu Tue Apr 18 15:55:20 2000 Received: from donkeykong.gpcc.itd.umich.edu (smtp@donkeykong.gpcc.itd.umich.edu [141.211.2.163]) by hub.org (8.9.3/8.9.3) with ESMTP id LAA51851 for ; Tue, 18 Apr 2000 11:55:20 -0400 (EDT) (envelope-from brita@umich.edu) Received: from joust.gpcc.itd.umich.edu (smtp@joust.gpcc.itd.umich.edu [141.211.2.148]) by donkeykong.gpcc.itd.umich.edu (8.8.8/4.3-mailhub) with ESMTP id LAA15698; Tue, 18 Apr 2000 11:54:13 -0400 (EDT) Received: from localhost (brita@localhost) by joust.gpcc.itd.umich.edu (8.8.8/5.1-client) with ESMTP id LAA29699; Tue, 18 Apr 2000 11:55:06 -0400 (EDT) Precedence: first-class Date: Tue, 18 Apr 2000 11:55:06 -0400 (EDT) From: Margarita Barvinok X-Sender: brita@joust.gpcc.itd.umich.edu To: ty cc: pgsql-admin@postgresql.org Subject: Re: DEFAULT now() ? In-Reply-To: <000e01bfa922$03466330$a20efea9@indus> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Archive-Number: 200004/69 On Tue, 18 Apr 2000, ty wrote: > May someone please show me the necessary code snippets that would allow the value of a column to take the current time ( ala now() ) by default on INSERT? > > Indicative example: > > CREATE TABLE foo ( > a INTEGER NOT NULL DEFAULT 0, > b DATETIME NOT NULL DEFAULT now() > ); > > INSERT INTO foo (a) VALUES (123); > > What happens here? Well, a row is inserted into table ``foo'' where ``a'' has the value 123 and b holds the date & time of when the create DDL statement was executed. I'm wondering how to get b to have the value of the time whenever any arbitrary insert statement is executed... > > Ty > > I think it works OK. This is my test: create table table1 (f1 int2 default 0 primary key, f2 timestamp default now(), f3 datetime default now() ); biology=> \d table1 Table = table1 +---------------------------+----------------------------------+-------+ | Field | Type |Length | +---------------------------+----------------------------------+-------+ | f1 | int2 not null default 0 |2 | | f2 | timestamp default now ( ) |4 | | f3 | datetime default now ( ) |8 | +---------------------------+----------------------------------+-------+ Index: table1_pkey biology=>insert into table1 (f1) values ('1'); biology=>insert into table1 (f1) values ('2'); biology=>insert into table1 (f1) values ('3'); and so on... biology=> select * from table1; f1|f2 |f3 --+----------------------+---------------------------- 1|2000-04-18 11:30:01-04|Tue Apr 18 11:30:01 2000 EDT 2|2000-04-18 11:30:18-04|Tue Apr 18 11:30:18 2000 EDT 3|2000-04-18 11:30:24-04|Tue Apr 18 11:30:24 2000 EDT 4|2000-04-18 11:30:28-04|Tue Apr 18 11:30:28 2000 EDT 7|2000-04-18 11:41:52-04|Tue Apr 18 11:41:52 2000 EDT 8|2000-04-18 11:41:59-04|Tue Apr 18 11:41:59 2000 EDT 9|2000-04-18 11:42:05-04|Tue Apr 18 11:42:05 2000 EDT (7 rows) -------------------------------------------------------- Margarita Barvinok University of Michigan System Administrator II Department of Biology brita@umich.edu ---------------------------------------------------------