Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 6406D475D6E for ; Thu, 9 Jan 2003 20:13:12 -0500 (EST) Received: from wolff.to (wolff.to [66.93.249.74]) by postgresql.org (Postfix) with SMTP id ADFE5475D17 for ; Thu, 9 Jan 2003 20:13:11 -0500 (EST) Received: (qmail 22294 invoked by uid 500); 10 Jan 2003 01:25:15 -0000 Date: Thu, 9 Jan 2003 19:25:15 -0600 From: Bruno Wolff III To: =?iso-8859-1?Q?Maur=EDcio?= Sessue Otta Cc: pgsql-sql@postgresql.org Subject: Re: Getting sequence value after inserting many rows at a time Message-ID: <20030110012515.GA22248@wolff.to> Mail-Followup-To: =?iso-8859-1?Q?Maur=EDcio?= Sessue Otta , pgsql-sql@postgresql.org References: <010901c2b841$f429f290$830101c0@mauricio1> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <010901c2b841$f429f290$830101c0@mauricio1> User-Agent: Mutt/1.3.25i X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200301/144 X-Sequence-Number: 11009 On Thu, Jan 09, 2003 at 22:48:11 -0200, Maurício Sessue Otta wrote: > Hi, > > I have a PHP script that do something like this: > > INSERT INTO table_with_sequence (field1, field2...., fieldn) > SELECT field1, field2, ..., fieldn FROM table,table > WHERE condition, condition > > My doubt: > Will the rows just inserted in "table_with_sequence" always be sequencial? > (won't it happen to have X rows from this INSERT, 1 rows from another INSERT > in the middle and the rest rows of the first INSERT?) > > How can I safely get the first value the INSERT "generated" for > the sequence? You might want to reconsider the design. You might want to use another serial column to indicate the grouping. This will allow you to pick out records inserted as a group.