Re: How do I get the rec-id from an insert.

From: Clinton Adams <clinton(at)vote-smart(dot)org>
To: Chris Ruprecht <chris(at)cdrbill(dot)com>, pgsql-php(at)postgresql(dot)org
Subject: Re: How do I get the rec-id from an insert.
Date: 2002-08-29 21:00:15
Message-ID: 200208291500.15392.clinton@vote-smart.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-php

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

In response to

Responses

Browse pgsql-php by date

  From Date Subject
Next Message Bruno Wolff III 2002-08-29 22:58:15 Re: How do I get the rec-id from an insert.
Previous Message Jean-Luc Lachance 2002-08-29 15:43:37 Re: Where can I get error messages?