Re: [GENERAL] Simple problem? - Mailing list pgsql-general

From Peter Eisentraut
Subject Re: [GENERAL] Simple problem?
Date
Msg-id Pine.GSO.4.02A.10003021614480.27493-100000@Dront.DoCS.UU.SE
Whole thread Raw
In response to Simple problem?  (Stan Jacobs <jacobs@jtek.com>)
Responses Re: [GENERAL] Simple problem?
Re: [GENERAL] Simple problem?
List pgsql-general
On Wed, 1 Mar 2000, Stan Jacobs wrote:

> I must be confusing my syntax somehow, because I'm having trouble doing a
> simple update with returned id...  As in.... I have two tables: an order
> table and an orderitems table.  I need to write the order record, then use
> the order_id from the order record in the insert to the orderitems record.

I assume you're using serial columns here. Table schemas always help ...

> 1. Can I use a transaction begin/end for the entire transaction if I need
> to get the order_id in between the two writes?

Sure.

> 2. How do I get the order_id from the record I just wrote?

You have to select it back out. A select on max(order_id) might do, but
you might get caught if someone else does updates on your table as well. I
am personally not so fond of serial columns because of this problem.

--
Peter Eisentraut                  Sernanders väg 10:115
peter_e@gmx.net                   75262 Uppsala
http://yi.org/peter-e/            Sweden


pgsql-general by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: [GENERAL] Version 7.0 beta problem
Next
From: Peter Eisentraut
Date:
Subject: Re: [GENERAL] More newbie question: Restructuring a table