pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Clinton Adams <clinton@vote-smart.org>
To: Chris Ruprecht <chris@cdrbill.com>
To: pgsql-php@postgresql.org
Subject: Re: How do I get the rec-id from an insert.
Date: Thu, 29 Aug 2002 15:00:15 -0600
Message-ID: <200208291500.15392.clinton@vote-smart.org> (raw)
In-Reply-To: <200208272340.17513.chris@cdrbill.com>
References: <200208272340.17513.chris@cdrbill.com>

Chris -

You don't really need to know the key values - make it one query:

insert into c values (nextval('crecid'), currval('arecid'), currval('brecid'))


On Tue August 27 2002 21:40, Chris Ruprecht graced us with the following -
> Hi all,
>
> I have 3 tables:
>
> a:
> a.recid
> a.name
>
> b:
> b.recid
> b.address
> b.city
>
> c:
> c.recid
> c.arecid
> c.brecid
>
>
> each has a default sequence on their respective recid - which is the
> primary index.
>
> when I do an "insert into a ...", it automagically assigns recid a new,
> unique value, same goes for b.
>
> But to create c, I need to know the recid from a and b, so I can connect
> the two.
> Is there any way to get the recid from a and b after they have been
> inserted like in "insert into a ... and give me the recid you're going to
> use, back"?
>
> I know, I can do a "netxval('...')" stuff and then insert the records with
> values in recid, but that requires two extra calls to the DB per
> transaction.
>
> Best regards,
> Chris




view thread (4+ messages)  latest in thread

Message-ID: <200208291500.15392.clinton@vote-smart.org>
Permalink:  ../200208291500.15392.clinton@vote-smart.org/
Also on:    postgresql.org/message-id/200208291500.15392.clinton@vote-smart.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-php@postgresql.org
  Cc: clinton@vote-smart.org, chris@cdrbill.com
  Subject: Re: How do I get the rec-id from an insert.
  In-Reply-To: <200208291500.15392.clinton@vote-smart.org>
  References: <200208272340.17513.chris@cdrbill.com> <200208291500.15392.clinton@vote-smart.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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