pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rod Taylor <pg@rbt.ca>
To: Andrei Bintintan <klodoma@ar-sd.net>
Cc: mixo <mixo@coza.net.za>
Cc: pgsql-sql@postgresql.org
Subject: Re: Last insert id
Date: Tue, 15 Jun 2004 06:30:08 -0400
Message-ID: <1087295408.27896.50.camel@jester> (raw)
In-Reply-To: <20040615070408.80EA4175A8@ar-sd.net>
References: <20040615070408.80EA4175A8@ar-sd.net>

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.





view thread (6+ messages)  latest in thread

Message-ID: <1087295408.27896.50.camel@jester>
Permalink:  ../1087295408.27896.50.camel@jester/
Also on:    postgresql.org/message-id/1087295408.27896.50.camel@jester

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: pg@rbt.ca, klodoma@ar-sd.net, mixo@coza.net.za
  Subject: Re: Last insert id
  In-Reply-To: <1087295408.27896.50.camel@jester>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox