Re: insert two tables taking serial from table1

From: Tino Wildenhain <tino(at)wildenhain(dot)de>
To: "Jim (s/nosp(at)m/(at)/ to reply)" <user725nosp(at)marpadeck(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: insert two tables taking serial from table1
Date: 2002-09-28 21:02:47
Message-ID: 99766266.1033254167@liza
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi Jim,

*google* *google* *google*

Does

http://www.phpbuilder.com/annotate/message.php3?id=1003450

Help you?

In short, you use nextval() on the first insert
and currval() for all subsequent inserts in referring
tables - this all in one transaction of course.

currval() only returns the value of your transactions
nextval() call! So if concurrent inserts appear,
they are not visible from inside your transaction.
(This way even your tablescan-aproach would work, but
its a performance hoog)

HTH
Tino Wildenhain

--On Samstag, 28. September 2002 01:17 +0000 "Jim (s/nosp(at)m/@/ to reply)"
<user725nosp(at)marpadeck(dot)com> wrote:

> I've been looking around for a way to set up an insert to table 1 then
> take the serial from table 1 that autoincrimented and add it to table 2.
> I've seen ways people have done it by grabbing last row of the table but
> I am concerned about a connection that doesn't need to add to table 2
> inserting into the last table before table 1 can be queried. and thus
> getting the relation to the wrong row. Is there a way to get the oid from
> the insert? using php incase that helps.
>
>
> thought about doing an exact search on what was just inserted but table
> has possibility of users adding exactly the same data. have thought about
> combining the tables but don't want an overgrown table with more rows
> then I can maneuver through.
>
> thanks in advance for any help.
> Jim
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Gerhard Häring 2002-09-29 02:39:49 Re: list of error code
Previous Message Marc G. Fournier 2002-09-28 20:19:15 Re: Contribution Problems...