Re: [GENERAL] Simple problem?

From: Peter Eisentraut <e99re41(at)DoCS(dot)UU(dot)SE>
To: Stan Jacobs <jacobs(at)jtek(dot)com>
Cc: pgsql-general(at)postgreSQL(dot)org
Subject: Re: [GENERAL] Simple problem?
Date: 2000-03-02 15:17:30
Message-ID: Pine.GSO.4.02A.10003021614480.27493-100000@Dront.DoCS.UU.SE
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)gmx(dot)net 75262 Uppsala
http://yi.org/peter-e/ Sweden

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Mark Jewiss 2000-03-02 15:23:44 Re: [GENERAL] Version 7.0 beta problem
Previous Message Peter Eisentraut 2000-03-02 15:14:10 Re: [GENERAL] Version 7.0 beta problem