Received: from oxmail.ox.ac.uk (oxmail3.ox.ac.uk [163.1.2.9]) by hub.org (8.9.3/8.9.3) with ESMTP id DAA81000 for ; Wed, 8 Sep 1999 03:15:57 -0400 (EDT) (envelope-from moray.mcconnachie@computing-services.oxford.ac.uk) Received: from heraldgate1.oucs.ox.ac.uk ([163.1.2.49] helo=frontend1.herald.ox.ac.uk ident=exim) by oxmail.ox.ac.uk with esmtp (Exim 2.10 #1) id 11ObxS-0005eV-00; Wed, 8 Sep 1999 08:15:54 +0100 Received: from max176.public.ox.ac.uk ([192.76.27.176] helo=max1.public.ox.ac.uk) by frontend1.herald.ox.ac.uk with smtp (Exim 2.02 #1) id 11ObxT-000201-00; Wed, 8 Sep 1999 08:15:55 +0100 Message-ID: <003001bef9c9$e813b160$0102a8c0@public.ox.ac.uk> From: "Moray McConnachie" To: "Hroi Sigurdsson" , References: <37D5CC72.9A7CBD49@ninja.dk> Subject: Re: [SQL] DEFAULT confusion Date: Wed, 8 Sep 1999 08:15:17 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.00.2314.1300 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 > Suppose i have the following sequence, table and index: > > CREATE SEQUENCE stuff_seq; > CREATE TABLE stuff ( > id INTEGER DEFAULT NEXTVAL('stuff_seq') NOT NULL, > name TEXT, > number INTEGER > ); > CREATE UNIQUE INDEX stuff_id ON tabel(id); > > Then to properly insert rows i have to > > INSERT INTO tabel VALUES (NEXTVAL('tabel_seq'), "sometext", 123); > > I can't just > INSERT INTO tabel VALUES (NULL, "something", 123); > > Then what is the point of the DEFAULT clause? In other words: How do I > get away with not specifying anything for id? It's not ideal, but if you make the sequence the last field in the table, e.g. CREATE TABLE tabel (this int2,that text,id serial) , then you can do a INSERT INTO tabel VALUES (5,'whatever); & that works. I would love to know if there is a 'proper' solution, though.