Change the behaviour of the SERIAL "Type"

From: Dani Oderbolz <oderbolz(at)ecologic(dot)de>
To: pgsql-sql(at)postgresql(dot)org
Subject: Change the behaviour of the SERIAL "Type"
Date: 2003-06-26 12:31:34
Message-ID: 3EFAE7A6.9070904@ecologic.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi all,
I am struggling hard with a badly written piece of code.
It has such statements all over the place:

INSERT INTO TABLE A (NULL, Value1, Value2...).

It was written for MySQL, which can take NULL and then assign an
auto_increment.
However, in PostgreSQL I am getting problems, because it would not let
me insert NULL
into a NOT NULL column (which is perfectly sensible from my point of view).
But as the author has also left out the column list in the insert, its
really tedious to change
the code.
Therefore I was thinking whether it was possible to change the meaning
of SERIAL in my DB,
so that it would actually generate a Trigger on the table, which would
then take care
of the SERIAL value. (Getting nextval from the sequence and write all
into the table)
This way, there would be no possibility to circumvent the Value which
comes from the Sequence.
To me, this would make more sense anyway than just setting the DEFAULT
of a coulmn
(and as far as I understood, this is what SERIAL does, right?)

Is there a way to change SERIAL this way?

Cheers, Dani

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Bruno Wolff III 2003-06-26 12:49:29 Re: Change the behaviour of the SERIAL "Type"
Previous Message Együd Csaba 2003-06-26 11:21:27 Join or Where?