Re: Migration problem - serial fields

From: Brent Verner <brent(at)rcfile(dot)org>
To: Rick Anderson <rick(at)planetdigital(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Migration problem - serial fields
Date: 2002-03-07 16:01:01
Message-ID: 20020307160101.GA80416@rcfile.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

[2002-03-04 14:07] Rick Anderson said:
| The snag I'm encountering is with Identity fields in SQL7. I discovered the
| equivalent in PG -- sequences/serial field. I would like to use serial if
| possible, but here's the problem: getting the existing records over while
| *keeping the existing values* for the Identity/sequence ID fields. They
| actually transfer over fine, but the next insert into the PG table
| generates a duplicate ID error. It seems obvious that my transfer did not
| update the sequence used by the serial field. However, I'm just not sure of
| the best course of action.

You need to use something like

db=> select setval('$A',(select max($B) from $C)+1);

where
$A = serial-sequence name
$B = serial column name
$C = table name

hth.
brent

--
"Develop your talent, man, and leave the world something. Records are
really gifts from people. To think that an artist would love you enough
to share his music with anyone is a beautiful thing." -- Duane Allman

In response to

Browse pgsql-general by date

  From Date Subject
Next Message daq 2002-03-07 16:18:02 Re: PL/pgSQL Syntax Problem
Previous Message Joerg Hessdoerfer 2002-03-07 15:55:58 Re: error