From: Bruce Momjian <pgman@candle.pha.pa.us>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Peter Eisentraut <peter_e@gmx.net>
Cc: Emils Klotins <emils@mail.usis.bkc.lv>
Cc: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] INSERT w/o variable names for a SERIAL type?
Date: Sun, 27 Feb 2000 14:04:42 -0500 (EST)
Message-ID: <200002271904.OAA01223@candle.pha.pa.us> (raw)
In-Reply-To: <9907.951676161@sss.pgh.pa.us>
> > 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: pgman@candle.pha.pa.us, tgl@sss.pgh.pa.us, peter_e@gmx.net, emils@mail.usis.bkc.lv
Subject: Re: [SQL] INSERT w/o variable names for a SERIAL type?
In-Reply-To: <200002271904.OAA01223@candle.pha.pa.us>
References: <9907.951676161@sss.pgh.pa.us> <200002271904.OAA01223@candle.pha.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox