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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





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


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux