Received: from mail.astrofoto.org (dsl092-102-177.nyc2.dsl.speakeasy.net [66.92.102.177]) by postgresql.org (8.11.3/8.11.4) with ESMTP id fAFK30m32701 for ; Thu, 15 Nov 2001 15:03:01 -0500 (EST) (envelope-from roland@astrofoto.org) Received: (from roland@localhost) by mail.astrofoto.org (8.11.6/8.11.6) id fAFK31L17739; Thu, 15 Nov 2001 15:03:01 -0500 To: pgsql-sql@postgresql.org Subject: Re: INSERT question References: <1f5f2b44.0111130130.17e8e57a@posting.google.com> <3bf19679$0$189$e4fe514c@newszilla.xs4all.nl> <878zd7vpzn.fsf@npa01zz001.simplot.com> From: Roland Roberts Date: 15 Nov 2001 15:03:00 -0500 In-Reply-To: <878zd7vpzn.fsf@npa01zz001.simplot.com> Message-ID: Lines: 21 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.0.105 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Archive-Number: 200111/224 X-Sequence-Number: 5607 >>>>> "Jason" == Jason Earl 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