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 D90F1D1C992 for ; Wed, 30 Jul 2003 02:20:37 +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 15295-06 for ; Tue, 29 Jul 2003 23:19:41 -0300 (ADT) Received: from candle.pha.pa.us (momjian.navpoint.com [207.106.42.251]) by svr1.postgresql.org (Postfix) with ESMTP id BAA3FD1C90E for ; Tue, 29 Jul 2003 23:20:33 -0300 (ADT) Received: (from pgman@localhost) by candle.pha.pa.us (8.11.6/8.11.6) id h6U2KGR12803; Tue, 29 Jul 2003 22:20:16 -0400 (EDT) From: Bruce Momjian Message-Id: <200307300220.h6U2KGR12803@candle.pha.pa.us> Subject: Re: Very strange 'now' behaviour in nested triggers. In-Reply-To: <4629.1059320950@sss.pgh.pa.us> To: Tom Lane Date: Tue, 29 Jul 2003 22:20:16 -0400 (EDT) Cc: Denis Zaitsev , pgsql-sql@postgresql.org X-Mailer: ELM [version 2.4ME+ PL99 (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200307/440 X-Sequence-Number: 14554 Could we cleanly convert 'now' to now()? I assume not because we pass the string to the date code, and have no way to pass back a function (now()). Having now and now() behave differently certainly is strange. CURRENT_TIMESTAMP works fine, but it does because it isn't in quotes. Strangely, CURRENT_TIMESTAMP converts to 'now', not now(). Is that a problem? | CURRENT_TIMESTAMP { /* * Translate as "'now'::text::timestamptz". * See comments for CURRENT_DATE. */ A_Const *s = makeNode(A_Const); TypeName *d; s->val.type = T_String; s->val.val.str = "now"; s->typename = SystemTypeName("text"); d = SystemTypeName("timestamptz"); /* SQL99 mandates a default precision of 6 for timestamp. * Also, that is about as precise as we will get since * we are using a microsecond time interface. * - thomas 2001-12-07 */ d->typmod = 6; $$ = (Node *)makeTypeCast((Node *)s, d); } --------------------------------------------------------------------------- Tom Lane wrote: > Denis Zaitsev writes: > > On Sat, Jul 26, 2003 at 10:31:44AM -0400, Tom Lane wrote: > >> 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. > > > Aaa... So, the INSERT inside a trigger will use the 'now' for the > > time this trigger is compiled (i.e. called first time)? Do I > > understand right? And the only outer trigger uses the right 'now' as > > its value goes from the top-level INSERT... > > Right. > > I put up a proposal in pgsql-hackers to change this behavior: > http://archives.postgresql.org/pgsql-hackers/2003-07/msg00818.php > If we made that change then the "wrong" way of defining the default > would fail in an obvious fashion --- the 'now' would get reduced to a > particular time immediately at CREATE TABLE. Doubtless this would annoy > some people, but the "right" way of defining the default isn't really > any harder, and it would save folks from getting burnt in corner cases, > like you were. > > Any comments? > > regards, tom lane > > ---------------------------(end of broadcast)--------------------------- > TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org > -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup. | Newtown Square, Pennsylvania 19073