Re: Getting sequence value after inserting many rows at a time

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Maurício Sessue Otta <mauricio(at)cristorei(dot)com(dot)br>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Getting sequence value after inserting many rows at a time
Date: 2003-01-10 01:25:15
Message-ID: 20030110012515.GA22248@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Thu, Jan 09, 2003 at 22:48:11 -0200,
Maurício Sessue Otta <mauricio(at)cristorei(dot)com(dot)br> 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.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Ron Peterson 2003-01-10 02:07:07 Re: insert rule doesn't see id field
Previous Message Maurício Sessue Otta 2003-01-10 00:48:11 Getting sequence value after inserting many rows at a time