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 D8AC4D1B182 for ; Wed, 9 Jun 2004 03:54:41 -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 17954-04 for ; Wed, 9 Jun 2004 06:54:38 +0000 (GMT) Received: from mailgate5.web.de (mailgate5.web.de [217.72.192.165]) by svr1.postgresql.org (Postfix) with ESMTP id 4AA2BD1B229 for ; Wed, 9 Jun 2004 03:54:34 -0300 (ADT) Received: by mailgate5.web.de (8.11.6p2/8.11.2/SuSE Linux 8.11.0-0.4) with SMTP id i596sJq30505; Wed, 9 Jun 2004 08:54:19 +0200 Received: from 217.72.192.194 by freemailng5202.web.de with HTTP; Wed, 09 Jun 2004 08:54:17 +0200 Date: Wed, 09 Jun 2004 08:54:17 +0200 Message-Id: <464355780@web.de> MIME-Version: 1.0 From: To: "mixo" Cc: pgsql-sql@postgresql.org Subject: Re: Last insert id Precedence: fm-user X-WEBDE-Sender: Organization: http://freemail.web.de/ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.3 tagged_above=0.0 required=5.0 tests=NO_REAL_NAME X-Spam-Level: X-Archive-Number: 200406/67 X-Sequence-Number: 18012 I'm new on postgreSQL, so this might not be the simplest sollution: Use a sequence instead of serial. After you have generated the new id with your_seq.nextval you can get thesame number again with your_seq.currval. details at http://www.postgresql.org/docs/7.3/static/functions-sequence.html mixo schrieb: >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 >