Re: INSERT question - Mailing list pgsql-sql

From Roland Roberts
Subject Re: INSERT question
Date
Msg-id m21yizhkej.fsf@tycho.rlent.pnet
Whole thread Raw
In response to Re: INSERT question  (Jason Earl <jason.earl@simplot.com>)
Responses Re: INSERT question  ("Andrew G. Hammond" <drew@xyzzy.dhs.org>)
Re: INSERT question  (Jason Earl <jason.earl@simplot.com>)
Re: INSERT question  ("Ross J. Reedstrom" <reedstrm@rice.edu>)
List pgsql-sql
>>>>> "Jason" == Jason Earl <jason.earl@simplot.com> writes:
   Jason> Even better, however, is to use the functions nextval() and   Jason> currval() like so:
   Jason> INSERT INTO parent_table (data) values ('some data');   Jason> INSERT INTO child_table (parent, more_data)
Jason>        (currval('parent_table_p_key_seq'),    Jason>          'more data');
 

The above is probably the best for a pure-SQL way with the caveat
that it should be wrapped in a transaction or currval() may not be
what you expect; i.e., another client may add a row and you get a
value different from what you inserted.

roland
--            PGP Key ID: 66 BC 3B CD
Roland B. Roberts, PhD                             RL Enterprises
roland@rlenter.com                     76-15 113th Street, Apt 3B
roland@astrofoto.org                       Forest Hills, NY 11375


pgsql-sql by date:

Previous
From: Jason Earl
Date:
Subject: Re: How to best grab a chunk of Ids from a sequence
Next
From: "Josh Berkus"
Date:
Subject: Re: PL/pgSQL examples NOT involving functions