Received: from candle.pha.pa.us (pgman@s5-03.ppp.op.net [209.152.195.67]) by hub.org (8.9.3/8.9.3) with ESMTP id OAA03703 for ; Sun, 27 Feb 2000 14:07:22 -0500 (EST) (envelope-from pgman@candle.pha.pa.us) Received: (from pgman@localhost) by candle.pha.pa.us (8.9.0/8.9.0) id OAA01223; Sun, 27 Feb 2000 14:04:52 -0500 (EST) From: Bruce Momjian Message-Id: <200002271904.OAA01223@candle.pha.pa.us> Subject: Re: [SQL] INSERT w/o variable names for a SERIAL type? In-Reply-To: <9907.951676161@sss.pgh.pa.us> from Tom Lane at "Feb 27, 2000 01:29:21 pm" To: Tom Lane Date: Sun, 27 Feb 2000 14:04:42 -0500 (EST) CC: Peter Eisentraut , Emils Klotins , pgsql-sql@postgreSQL.org X-Mailer: ELM [version 2.4ME+ PL72 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit > > INSERT INTO my_table VALUES (a, b, c, DEFAULT, x, y, z, ...); > > I think that is legal SQL92 syntax, but Postgres doesn't accept it > at present. > > The usual recommendation is to call out the columns you are loading > explicitly: > > INSERT INTO my_table(a,b,d) VALUES (val-for-a, val-for-b, val-for-d); > > The ones you don't load get their default values substituted instead. > > This way is a shade more verbose, but it's good solid defensive > programming practice: the insert will do what it's supposed to > even if the table schema changes to add/delete/reorder columns. The problem is when you are inserting >50 columns, it is a pain. The use of DEFAULT would also allow SERIAL columns to get the proper nextval(), rather than having specify the nextval() call specifically. Added to TODO. -- Bruce Momjian | http://www.op.net/~candle pgman@candle.pha.pa.us | (610) 853-3000 + If your life is a hard drive, | 830 Blythe Avenue + Christ can be your backup. | Drexel Hill, Pennsylvania 19026