Received: from infbssys.ips.cs.tu-bs.de (root@infbssys.ips.cs.tu-bs.de [134.169.32.1]) by hub.org (8.9.3/8.9.3) with ESMTP id JAA39073 for ; Wed, 8 Sep 1999 09:51:44 -0400 (EDT) (envelope-from mack@ips.cs.tu-bs.de) Received: from infbsdb1.idb.cs.tu-bs.de (infbsdb1.idb.cs.tu-bs.de [134.169.32.131]) by infbssys.ips.cs.tu-bs.de (8.9.3/8.9.3) with ESMTP id PAA22085 for ; Wed, 8 Sep 1999 15:51:40 +0200 From: Thomas Mack Date: Wed, 8 Sep 1999 15:51:39 +0200 (MET DST) Message-Id: <199909081351.PAA10356@infbsdb1.idb.cs.tu-bs.de> To: pgsql-sql@postgreSQL.org Subject: Re: [SQL] DEFAULT confusion >> 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. > Well - normally you specify your column names in an insert, if you don't want to fill all values or if you are unsure about the sequence of attributes: ------------------------------------------------------------ mack=> CREATE SEQUENCE stuff_seq; CREATE mack=> CREATE TABLE stuff ( mack-> id INTEGER DEFAULT NEXTVAL('stuff_seq') NOT NULL, mack-> name TEXT, mack-> number INTEGER mack-> ); CREATE mack=> insert into stuff (name, number) values ('something', 123); INSERT 1403035 1 mack=> select * from stuff; id|name |number --+---------+------ 1|something| 123 (1 row) mack=> ------------------------------------------------------------ Thomas Mack TU Braunschweig, Abt. Informationssysteme