Re: Import id column then convert to SEQUENCE?

From: Vick Khera <vivek(at)khera(dot)org>
To: pgsql <pgsql-general(at)postgresql(dot)org>
Subject: Re: Import id column then convert to SEQUENCE?
Date: 2010-12-10 20:08:11
Message-ID: AANLkTiksWTWcfgmaezbWfLa1ZrD5_yOEZ60zuV-NkL7_@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Dec 9, 2010 at 10:56 PM, Shoaib Mir <shoaibmir(at)gmail(dot)com> wrote:
> I guess I misread it... use the following:
>
> - Import all the data into say an integer column.
> - Now create a sequence and give it a start value of where your import
> ended.
> - Make the default value for the column using the new sequence.
>

create the table with a SERIAL column, which will make the sequence
and set the auto increment default as you wanted.

import the data

update the sequence with setval() to the next highest value you want
it to return, usually max()+1 of the populated column.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message jan 2010-12-10 22:51:31 pg_dump order of rows
Previous Message Vick Khera 2010-12-10 20:05:26 Re: Invalid byte sequence