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 87891D1B1C8 for ; Tue, 15 Jun 2004 04:05:38 -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 68434-03 for ; Tue, 15 Jun 2004 07:05:36 +0000 (GMT) Received: from ar-sd.net (unknown [81.196.32.112]) by svr1.postgresql.org (Postfix) with ESMTP id 044B0D1B182 for ; Tue, 15 Jun 2004 04:05:32 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by ar-sd.net (Postfix) with ESMTP id AF80E17656; Tue, 15 Jun 2004 10:04:08 +0300 (EEST) Received: from forge (unknown [192.168.0.11]) by ar-sd.net (Postfix) with ESMTP id 80EA4175A8; Tue, 15 Jun 2004 10:04:08 +0300 (EEST) From: "Andrei Bintintan" To: "'mixo'" , Subject: Re: Last insert id Date: Tue, 15 Jun 2004 10:05:40 +0300 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook, Build 11.0.5510 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2739.300 In-Reply-To: <40C6AD19.70302@coza.net.za> thread-index: AcRN7AXpt1k3peupRti/3YWM12PU2AEuvQuQ Message-Id: <20040615070408.80EA4175A8@ar-sd.net> X-Virus-Scanned: by AMaViS snapshot-20020531 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/131 X-Sequence-Number: 18076 "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@postgresql.org [mailto:pgsql-sql-owner@postgresql.org] On Behalf Of mixo Sent: Wednesday, June 09, 2004 9:24 AM To: pgsql-sql@postgresql.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