Re: [GENERAL] Simple problem?

Поиск
Список
Период
Сортировка
Искать
От
Peter Eisentraut
Тема
Re: [GENERAL] Simple problem?
Дата
Msg-id
Pine.GSO.4.02A.10003021614480.27493-100000@Dront.DoCS.UU.SE
Ответ на
Simple problem? (Stan Jacobs)
Список
Дерево обсуждения
Simple problem? Stan Jacobs <jacobs@jtek.com>
Re: [GENERAL] Simple problem? Peter Eisentraut <e99re41@DoCS.UU.SE>
Re: [GENERAL] Simple problem? "Ross J. Reedstrom" <reedstrm@wallace.ece.rice.edu>
Re: [GENERAL] Simple problem? Peter Eisentraut <e99re41@DoCS.UU.SE>
Re: [GENERAL] Simple problem? <kaiq@realtyideas.com>
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 по дате отправления
От: Peter Eisentraut
Дата:
От: Peter Eisentraut
Дата:
FAQ