Thread: insert two tables taking serial from table1

insert two tables taking serial from table1

From
"Jim (s/nosp@m/@/ to reply)"
Date:
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



Re: insert two tables taking serial from table1

From
Tino Wildenhain
Date:
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@m/@/ to reply)"
<user725nosp@marpadeck.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@postgresql.org so that your
> message can get through to the mailing list cleanly