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

From: "Ben K(dot)" <bkim(at)coe(dot)tamu(dot)edu>
To: pgsql-admin(at)postgresql(dot)org
Subject: Re: How to enforce the use of the sequence for serial columns
Date: 2006-12-14 11:57:57
Message-ID: Pine.GSO.4.64.0612140543270.20249@coe.tamu.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Jerry Sievers 2006-12-14 12:30:46 Re: How to enforce the use of the sequence for serial columns
Previous Message Eduardo J. Ortega 2006-12-14 10:28:18 Re: Backup