X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 66DF0D1B262 for ; Tue, 15 Jun 2004 07:30:15 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 55694-05 for ; Tue, 15 Jun 2004 10:30:11 +0000 (GMT) Received: from tht.net (vista.tht.net [216.126.88.2]) by svr1.postgresql.org (Postfix) with ESMTP id 59D0DD1B7CC for ; Tue, 15 Jun 2004 07:30:07 -0300 (ADT) Received: from [134.22.68.4] (dyn-68-4.tor.dsl.tht.net [134.22.68.4]) by tht.net (Postfix) with ESMTP id 13D0876A53; Tue, 15 Jun 2004 06:30:10 -0400 (EDT) Subject: Re: Last insert id From: Rod Taylor To: Andrei Bintintan Cc: 'mixo' , pgsql-sql@postgresql.org In-Reply-To: <20040615070408.80EA4175A8@ar-sd.net> References: <20040615070408.80EA4175A8@ar-sd.net> Content-Type: text/plain Message-Id: <1087295408.27896.50.camel@jester> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 Date: Tue, 15 Jun 2004 06:30:08 -0400 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200406/132 X-Sequence-Number: 18077 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.