Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id F10D59FA364 for ; Thu, 14 Dec 2006 08:02:03 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-new, port 10024) with ESMTP id 68395-04 for ; Thu, 14 Dec 2006 08:01:49 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from coe.tamu.edu (edsun.coe.tamu.edu [165.91.232.6]) by postgresql.org (Postfix) with ESMTP id 19E729F9F46 for ; Thu, 14 Dec 2006 08:01:58 -0400 (AST) Received: (from root@localhost) by coe.tamu.edu (8.11.7p2+Sun/8.12.11) id kBEBwu920731 for pgsql-admin@postgresql.org; Thu, 14 Dec 2006 05:58:56 -0600 (CST) Received: from coe.tamu.edu (coe.tamu.edu [165.91.232.6]) by coe.tamu.edu (8.11.7p2+Sun/8.12.11) with ESMTP id kBEBvvC20714 for ; Thu, 14 Dec 2006 05:57:57 -0600 (CST) Date: Thu, 14 Dec 2006 05:57:57 -0600 (CST) From: "Ben K." To: pgsql-admin@postgresql.org Subject: Re: How to enforce the use of the sequence for serial columns Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: by AMaViS 0.3.12 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200612/200 X-Sequence-Number: 23992 > 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