RE: Serial field - Mailing list pgsql-novice

From Sykora, Dale
Subject RE: Serial field
Date
Msg-id 898CFC137378DD44826AC0AAAA5F7BD918E19B@cceexc22.americas.cpqcorp.net
Whole thread Raw
In response to Serial field  (Francois Thomas <FrancoisT@alsdesign.fr>)
List pgsql-novice
Francois,
    It sounds like you want your migrated data to keep their sequence
values but have new records have n+1 as the sequence value where n is the
largest previous sequence value.  Here is how I would approach this problem.
Create a new table with a serial(sequence) and other fields.  Write a perl
script to read and sort your migration data by sequence number and then
output a sql command file to insert the migrated data 1 row at a time
setting the sequence nextval appropriately before each insert.  Run the sql
file via psql.  Now your table has the migrated data with correct sequence
values and future inserts will work normally.

Thanks,
Dale


> --- Francois Thomas <FrancoisT@alsdesign.fr> wrote:
> >
> > Hello to all
> >
> > Unable to find an answer by searching the list
> > archive, I ask my question
> > here:
> > I want to migrate a database to PostgreSQL 6.5.2
> > I need an auto-increment field. I first tried the
> > SERIAL type, but it
> > doesn't fit my needs.
> > In fact, I want to:
> > 1/ keep the original INT value of my existing
> > records from another server
> > (say, first row can be "1", second "3", next one
> > "17",...)
> > 2/ have an automatic incrementation of the last
> > value for a new record. For
> > exemple, with the values above and a SERIAL field,
> > the default value for a
> > new field would be "1" (first use of the sequence)
> > instead of "18" (last
> > value+1)..
> > I hope my english is not too obscure !
> > Any advice will be welcome
> > Regards
> >
> > --
> > François THOMAS
> >
> > ---------------------------(end of
> > broadcast)---------------------------
> > TIP 6: Have you searched our list archives?
> >
> > http://www.postgresql.org/search.mpl
>
>
> __________________________________________________
> Do You Yahoo!?
> Get personalized email addresses from Yahoo! Mail
> http://personal.mail.yahoo.com/
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html
>

pgsql-novice by date:

Previous
From: Francois Thomas
Date:
Subject: TR: Serial field
Next
From: jim davis
Date:
Subject: Re: [ODBC] fatal ODBC error?