RE: Serial field

From: "Sykora, Dale" <Dale(dot)Sykora(at)COMPAQ(dot)com>
To: Francois Thomas <FrancoisT(at)alsdesign(dot)fr>, "'pgsql-novice(at)postgresql(dot)org'" <pgsql-novice(at)postgresql(dot)org>
Subject: RE: Serial field
Date: 2001-07-13 15:18:30
Message-ID: 898CFC137378DD44826AC0AAAA5F7BD918E19B@cceexc22.americas.cpqcorp.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)alsdesign(dot)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
>

Browse pgsql-novice by date

  From Date Subject
Next Message jim davis 2001-07-13 15:35:04 Re: [ODBC] fatal ODBC error?
Previous Message Francois Thomas 2001-07-13 09:00:15 TR: Serial field