Re: Last insert id - Mailing list pgsql-sql

From Rod Taylor
Subject Re: Last insert id
Date
Msg-id 1087295408.27896.50.camel@jester
Whole thread Raw
In response to Re: Last insert id  ("Andrei Bintintan" <klodoma@ar-sd.net>)
List pgsql-sql
On Tue, 2004-06-15 at 03:05, Andrei Bintintan wrote:
> "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).

No, this is not safe outside of the serializable isolation.

rbt=# begin;
BEGIN
rbt=# select max(id) from l;max
-----  1
(1 row)

rbt=# insert into l values (2);
INSERT 62597 1
rbt=# select max(id) from l;max
-----  3
(1 row)

rbt=# commit;
COMMIT

I inserted 3 from another connection after 2 was inserted.




pgsql-sql by date:

Previous
From: "Andrei Bintintan"
Date:
Subject: Re: Last insert id
Next
From: "Jie Liang"
Date:
Subject: Re: Prepare Statement