Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id B415A475AA5 for ; Thu, 13 Jun 2002 18:35:17 -0400 (EDT) Received: from linuxmail.lgsinc.com (unknown [12.22.4.163]) by postgresql.org (Postfix) with ESMTP id 0C575477353 for ; Thu, 13 Jun 2002 17:42:35 -0400 (EDT) Received: from timetop ([10.13.15.254]) by linuxmail.lgsinc.com (8.11.0/8.8.7) with SMTP id g5DLfX116578; Thu, 13 Jun 2002 14:41:39 -0700 Date: Thu, 13 Jun 2002 14:32:13 -0700 From: Tim Ellis To: Tom Lane Cc: pgsql-admin@postgresql.org Subject: Re: Triggers... Questions... Yes. Message-Id: <20020613143213.1d375e2f.Tim.Ellis@gamet.com> In-Reply-To: <29650.1024002262@sss.pgh.pa.us> References: <20020613124835.6e182cd4.Tim.Ellis@gamet.com> <29650.1024002262@sss.pgh.pa.us> Organization: Gamet X-Mailer: Sylpheed version 0.7.4 (GTK+ 1.2.10; i586-mandrake-linux-gnu) WerdupHomey: 3.14159265358979323 Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Archive-Number: 200206/95 X-Sequence-Number: 4530 > > 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. That explains a lot of things. About this DDL problem and Dezign for Databases both. > > set (n.autonum) = (select (max(autonum),0) + 1 from transaction); > > 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? Yeh. Good question. I would assume their generator MEANT (max(autonum,0)+1) supposing that a "ANSI Level 2"-compliant server's max function might return the second value if the first is NULL. But no matter how you slice it, that looks syntactically wrong. > 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... Perhaps. Is the sequence object part of standard SQL? I know Postgres and Oracle have it (among others) but I also know of at least one major recent-version RDBMS that fails to have a sequence object. On the topic of max(x), there are certain RDBMSs that implement a max(x) in such a way that the optimiser will, supposing x has an index on it, use the index to determine max(x) rather than a table scan. I noticed during porting an from Sybase to Postgres this particular problem when my select max(x) from tableY queries were running very slowly. -- Tim Ellis DBA, Gamet