Re: [SQL] INSERT w/o variable names for a SERIAL type? - Mailing list pgsql-sql

From Bruce Momjian
Subject Re: [SQL] INSERT w/o variable names for a SERIAL type?
Date
Msg-id 200002271904.OAA01223@candle.pha.pa.us
Whole thread Raw
In response to Re: [SQL] INSERT w/o variable names for a SERIAL type?  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: [SQL] INSERT w/o variable names for a SERIAL type?  ("Ross J. Reedstrom" <reedstrm@wallace.ece.rice.edu>)
List pgsql-sql
> > 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,
Pennsylvania19026
 


pgsql-sql by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: [SQL] INSERT w/o variable names for a SERIAL type?
Next
From: "Ross J. Reedstrom"
Date:
Subject: Re: [SQL] INSERT w/o variable names for a SERIAL type?