Change the behaviour of the SERIAL "Type"

Поиск
Список
Период
Сортировка
От Dani Oderbolz
Тема Change the behaviour of the SERIAL "Type"
Дата
Msg-id 3EFAE7A6.9070904@ecologic.de
обсуждение исходный текст
Ответы Re: Change the behaviour of the SERIAL "Type"  (Bruno Wolff III <bruno@wolff.to>)
Список 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 по дате отправления:

Предыдущее
От: Együd Csaba
Дата:
Сообщение: Join or Where?
Следующее
От: Bruno Wolff III
Дата:
Сообщение: Re: Change the behaviour of the SERIAL "Type"