From: Tim Ellis <Tim.Ellis@gamet.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-admin@postgresql.org
Subject: Re: Triggers... Questions... Yes.
Date: Thu, 13 Jun 2002 14:32:13 -0700
Message-ID: <20020613143213.1d375e2f.Tim.Ellis@gamet.com> (raw)
In-Reply-To: <29650.1024002262@sss.pgh.pa.us>
References: <20020613124835.6e182cd4.Tim.Ellis@gamet.com>
<29650.1024002262@sss.pgh.pa.us>
> > 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
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: Tim.Ellis@gamet.com, tgl@sss.pgh.pa.us
Subject: Re: Triggers... Questions... Yes.
In-Reply-To: <20020613143213.1d375e2f.Tim.Ellis@gamet.com>
References: <20020613124835.6e182cd4.Tim.Ellis@gamet.com> <29650.1024002262@sss.pgh.pa.us> <20020613143213.1d375e2f.Tim.Ellis@gamet.com>
* 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