Re: Migration problem - serial fields - Mailing list pgsql-general

From Brent Verner
Subject Re: Migration problem - serial fields
Date
Msg-id 20020307160101.GA80416@rcfile.org
Whole thread Raw
In response to Migration problem - serial fields  ("Rick Anderson" <rick@planetdigital.com>)
List 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

pgsql-general by date:

Previous
From: Joerg Hessdoerfer
Date:
Subject: Re: How do I pass the -i option during boot time?
Next
From: Tom Lane
Date:
Subject: Re: Explain SQL feature