pg.ddx.io pgsql-sql@postgresql.org mailing list archivehelp / color / mirror / Atom feed
insert default into serial fields? 2+ messages / 2 participants [nested] [flat]
* insert default into serial fields? @ 2000-03-07 07:22 Seth Banks <seth@subimage.com> 2000-03-07 08:36 ` Re: [SQL] insert default into serial fields? Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 1 reply; 2+ messages in thread From: Seth Banks @ 2000-03-07 07:22 UTC (permalink / raw) To: pgsql-sql what's the appropriate way to go about inserting values into a table with a serial field? i have tried '', 'default', and default...but none seem to work correctly. any help? ^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: [SQL] insert default into serial fields? 2000-03-07 07:22 insert default into serial fields? Seth Banks <seth@subimage.com> @ 2000-03-07 08:36 ` Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 2+ messages in thread From: Tom Lane @ 2000-03-07 08:36 UTC (permalink / raw) To: Seth Banks <seth@subimage.com>; +Cc: pgsql-sql "Seth Banks" <seth@subimage.com> writes: > what's the appropriate way to go about inserting values into a table with a > serial field? > i have tried '', 'default', and default...but none seem to work correctly. > any help? INSERT ... VALUES(..., DEFAULT, ...) ought to work according to SQL92, but we don't support it currently. I recommend using an explicit column list in INSERT: INSERT INTO table(col1,col2,col4) VALUES(val1,val2,val4) where you omit the serial column's name (col3, maybe, in this example). Another way is to explicitly give the same expression as the column's default value: nextval('sequence-object-name'). But that's pretty ugly because it ties your code to the current implementation of SERIAL. One great advantage of explicitly listing the column names is that your INSERT code doesn't break if you add or reorder columns in the table declaration. IMHO that makes up for the tedium of writing them all out, but you might see it differently... regards, tom lane ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2000-03-07 08:36 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2000-03-07 07:22 insert default into serial fields? Seth Banks <seth@subimage.com> 2000-03-07 08:36 ` Tom Lane <tgl@sss.pgh.pa.us>
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