From: Tom Lane <tgl@sss.pgh.pa.us>
To: 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 13:29:21 -0500
Message-ID: <9907.951676161@sss.pgh.pa.us> (raw)
In-Reply-To: <Pine.LNX.4.21.0002260418130.3063-100000@localhost.localdomain>
References: <Pine.LNX.4.21.0002260418130.3063-100000@localhost.localdomain>
Peter Eisentraut <peter_e@gmx.net> writes:
> Emils Klotins writes:
>> Now, if I want to write a general #define, I'd need to have a way
>> to specify 'default' for SERIAL field, for, if I omit the id field in
>> VALUES, I need to specify all the rest of the fields explicitly.
>>
>> Is there any value I could put in place of id in VALUES part, to
>> make it replaced with the next value in sequence?
> 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.
regards, tom lane
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: 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: <9907.951676161@sss.pgh.pa.us>
References: <Pine.LNX.4.21.0002260418130.3063-100000@localhost.localdomain> <9907.951676161@sss.pgh.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