Change the behaviour of the SERIAL "Type" - Mailing list pgsql-sql

From Dani Oderbolz
Subject Change the behaviour of the SERIAL "Type"
Date
Msg-id 3EFAE7A6.9070904@ecologic.de
Whole thread Raw
Responses Re: Change the behaviour of the SERIAL "Type"
List 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



pgsql-sql by date:

Previous
From: Együd Csaba
Date:
Subject: Join or Where?
Next
From: Bruno Wolff III
Date:
Subject: Re: Change the behaviour of the SERIAL "Type"