RE: [SQL] Getting primary key from insert statement

From: Herouth Maoz <herouth(at)oumail(dot)openu(dot)ac(dot)il>
To: Michael J Davis <michael(dot)j(dot)davis(at)tvguide(dot)com>, pgsql-sql(at)postgreSQL(dot)org
Subject: RE: [SQL] Getting primary key from insert statement
Date: 1999-06-08 16:40:17
Message-ID: l03130302b382f5c2b12e@[147.233.159.109]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

At 19:23 +0300 on 08/06/1999, Michael J Davis wrote:

> I accomplish this by trapping the "Before Insert" event in the form used to
> add new Status records (the user is NOT entering the StatusID) and doing the
> following:
>
> Form.StatusID = getSeqValue('Status_seq')

Thus, you do it in the frontend. Six months later, a programmer writes
another form that accesses the same table, and fails to do so, or leaves it
to the user. Or he decides that he has a better number generator to use.
There are errors. Perhaps his form generates numbers which the sequence has
not yet reached. Conflicts ocuur. Boss unhappy.

That happens because you failed to centralize the logic of your database.

As I said, the "serial" datatype is not a complete fail-safe, because it
still allows entering non-sequence values. But at least it's a step in the
right direction. Putting the logic in the client side is the wrong thing to
do.

To finish in a humorous note, I wouldn't use programming practices
encouraged by Microsoft products as pillars of truth...

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Bob Kruger 1999-06-08 17:27:30 Updating non atomic values
Previous Message Michael J Davis 1999-06-08 16:23:14 RE: [SQL] Getting primary key from insert statement