Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id 1B6BB476FD1 for ; Thu, 13 Jun 2002 17:22:28 -0400 (EDT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id 5833D476B74 for ; Thu, 13 Jun 2002 17:04:25 -0400 (EDT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.11.4/8.11.4) with ESMTP id g5DL4Mb29653; Thu, 13 Jun 2002 17:04:23 -0400 (EDT) To: Tim Ellis Cc: pgsql-admin@postgresql.org Subject: Re: Triggers... Questions... Yes. In-reply-to: <20020613124835.6e182cd4.Tim.Ellis@gamet.com> References: <20020613124835.6e182cd4.Tim.Ellis@gamet.com> Comments: In-reply-to Tim Ellis message dated "Thu, 13 Jun 2002 12:48:35 -0700" Date: Thu, 13 Jun 2002 17:04:22 -0400 Message-ID: <29650.1024002262@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200206/93 X-Sequence-Number: 4528 Tim Ellis writes: > I just used Dezign for Databases and created a simple table in what it > claimed was "ANSI Level 2" compliance with a one-up "autonum" column. There is no such animal as "ANSI Level 2" SQL. > create trigger transaction_autonum_inc > before insert on transaction > referencing new as n > for each row > set (n.autonum) = (select (max(autonum),0) + 1 from transaction); Looking at SQL99 (that's ISO/IEC 9075-2:1999, Part 2: SQL/Foundation if we have to get pedantic about it), there is something about a "referencing" clause, which we do not have. However, the "set" command shown here does not appear to be legal according to SQL99, so I'm not planning to get excited about not having "referencing". There are a number of missing features in our trigger stuff, and that one seems right at the bottom of the list as far as adding useful functionality goes. BTW, what are they expecting "(max(autonum),0)" to do, other than draw a syntax error? Perhaps there was supposed to be a COALESCE there? Even if it worked or were standards-compliant, this approach to implementing an autonumbering column would be brain dead in the extreme --- you do *not* want to do a max() aggregate for every insert. Use a sequence object instead... regards, tom lane