pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Tim Ellis <Tim.Ellis@gamet.com>
Cc: pgsql-admin@postgresql.org
Subject: Re: Triggers... Questions... Yes.
Date: Thu, 13 Jun 2002 17:04:22 -0400
Message-ID: <29650.1024002262@sss.pgh.pa.us> (raw)
In-Reply-To: <20020613124835.6e182cd4.Tim.Ellis@gamet.com>
References: <20020613124835.6e182cd4.Tim.Ellis@gamet.com>

Tim Ellis <Tim.Ellis@gamet.com> 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



view thread (5+ messages)  latest in thread

Message-ID: <29650.1024002262@sss.pgh.pa.us>
Permalink:  ../29650.1024002262@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/29650.1024002262@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: tgl@sss.pgh.pa.us, Tim.Ellis@gamet.com
  Subject: Re: Triggers... Questions... Yes.
  In-Reply-To: <29650.1024002262@sss.pgh.pa.us>
  References: <20020613124835.6e182cd4.Tim.Ellis@gamet.com> <29650.1024002262@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox