| From: | Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> | 
|---|---|
| To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> | 
| Cc: | Peter Eisentraut <peter_e(at)gmx(dot)net>, Emils Klotins <emils(at)mail(dot)usis(dot)bkc(dot)lv>, pgsql-sql(at)postgreSQL(dot)org | 
| Subject: | Re: [SQL] INSERT w/o variable names for a SERIAL type? | 
| Date: | 2000-02-27 19:04:42 | 
| Message-ID: | 200002271904.OAA01223@candle.pha.pa.us | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | 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(at)candle(dot)pha(dot)pa(dot)us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Ross J. Reedstrom | 2000-02-27 19:44:02 | Re: [SQL] INSERT w/o variable names for a SERIAL type? | 
| Previous Message | Bruce Momjian | 2000-02-27 18:58:43 | Re: [SQL] INSERT w/o variable names for a SERIAL type? |