Skip site navigation (1) Skip section navigation (2)

Re: Last insert id

From: "Andrei Bintintan" <klodoma(at)ar-sd(dot)net>
To: "'mixo'" <mixo(at)coza(dot)net(dot)za>, <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Last insert id
Date: 2004-06-15 07:05:40
Message-ID: 20040615070408.80EA4175A8@ar-sd.net (view raw or flat)
Thread:
Lists: pgsql-sql
"Is it safe to use "select max(table1_id) from table1" after the insert?"

Yes it is safe, but ONLY if you use it inside a transaction.(BEGIN/COMMIT).

BR.


-----Original Message-----
From: pgsql-sql-owner(at)postgresql(dot)org [mailto:pgsql-sql-owner(at)postgresql(dot)org]
On Behalf Of mixo
Sent: Wednesday, June 09, 2004 9:24 AM
To: pgsql-sql(at)postgresql(dot)org
Subject: [SQL] Last insert id

I have three tables which are related a serial field, table1_id, in on of
the tables. Updating the tables is done through a transaction. My problem
is, once I have insert  a row in the first tables with table1_id, I need for
the other two tables. How can I get this? Is it safe to use "select
max(table1_id) from table1" after the insert?

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faqs/FAQ.html



In response to

Responses

pgsql-sql by date

Next:From: Rod TaylorDate: 2004-06-15 10:30:08
Subject: Re: Last insert id
Previous:From: Jie LiangDate: 2004-06-14 23:32:57
Subject: Prepare Statement

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group