Re: How to enforce the use of the sequence for serial columns

Поиск
Список
Период
Сортировка
От Ben K.
Тема Re: How to enforce the use of the sequence for serial columns
Дата
Msg-id Pine.GSO.4.64.0612130844060.5840@coe.tamu.edu
обсуждение исходный текст
Список pgsql-admin
"Marc Mamin" <M.Mamin@intershop.de> writes:
> I'd like to ensure that nobody provide the ID in an insert statement
> when the id is linked to a sequence.
> I tried it with a trigger, but the id value is fed before the "BEFORE
> INSERT" test is performed (see below)...

If you have the luxury of re-creating the table (dump, edit schema,
reload), you might want to try this:

create table mytable (myid serial primary key constraint mytable_myid_chk check (myid =
currval('mytable_myid_seq'), mydata varchar(255), ...);

This will prevent "serial" id field from being arbitrarily manipulated
outside the sequence..

There may be an equivalent way using alter table, but on a first look, currval
cannot be used to check existing values.


Regards

Ben K.
Developer
http://benix.tamu.edu




В списке pgsql-admin по дате отправления:

Предыдущее
От: Jerry Sievers
Дата:
Сообщение: Re: How to enforce the use of the sequence for serial columns ?
Следующее
От: Antonios Katsikadamos
Дата:
Сообщение: storage