X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id CBB33D1C92F for ; Sat, 26 Jul 2003 14:32:57 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 35636-09 for ; Sat, 26 Jul 2003 11:32:11 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id B0FBBD1C4EB for ; Sat, 26 Jul 2003 11:32:55 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h6QEVjQ3009413; Sat, 26 Jul 2003 10:31:45 -0400 (EDT) To: Denis Zaitsev Cc: pgsql-sql@postgresql.org Subject: Re: Very strange 'now' behaviour in nested triggers. In-reply-to: <20030726193947.B1636@natasha.ward.six> References: <20030726193947.B1636@natasha.ward.six> Comments: In-reply-to Denis Zaitsev message dated "Sat, 26 Jul 2003 19:39:47 +0600" Date: Sat, 26 Jul 2003 10:31:44 -0400 Message-ID: <9412.1059229904@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200307/397 X-Sequence-Number: 14511 Denis Zaitsev writes: > create table xxx ( > s text, > t timestamp > default 'now' > ); That's a dangerous way to define the default --- 'now' is taken as a literal of type timestamp, which means it will be reduced to a timestamp constant as soon as a statement that requires the default is planned. You lose in plpgsql because of plan caching, but you'd also lose if you tried to PREPARE the insert command. Example: regression=# insert into xxx values('a'); INSERT 154541 1 regression=# insert into xxx values('b'); INSERT 154542 1 regression=# prepare s(text) as insert into xxx values($1); PREPARE regression=# execute s('q1'); EXECUTE regression=# execute s('q2'); EXECUTE regression=# select * from xxx; s | t ----+---------------------------- a | 2003-07-26 10:18:51.364913 b | 2003-07-26 10:18:53.519648 q1 | 2003-07-26 10:19:21.795415 q2 | 2003-07-26 10:19:21.795415 (4 rows) The default would work the way you want with almost any other way of doing it. For instance default now() default current_timestamp default localtimestamp default 'now'::text Given that you want timestamp without time zone, I'd probably use "default localtimestamp". regards, tom lane