Re: How to enforce the use of the sequence for serial columns - Mailing list pgsql-admin

From Ben K.
Subject Re: How to enforce the use of the sequence for serial columns
Date
Msg-id Pine.GSO.4.64.0612140543270.20249@coe.tamu.edu
Whole thread Raw
Responses Re: How to enforce the use of the sequence for serial columns
List pgsql-admin

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


I'd like to clarify that this will not be a full solution, since it will
not allow update of the table unless nextval has been used in the same
sequence already.

There seems to be a hack in case of oracle that allows using currval
without nextval, but it's a hack and I don't know if there's an equivalent
in postgresql (http://rootshell.be/~yong321/computer/sequence.txt).
(Oracle seems to have "disable" option when adding check constraint by
alter table, but the context seem a bit different from ours so may not be
useful in our case, at any rate.)




Regards

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




---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

pgsql-admin by date:

Previous
From: "Eduardo J. Ortega"
Date:
Subject: Re: Backup
Next
From: Jerry Sievers
Date:
Subject: Re: How to enforce the use of the sequence for serial columns