[prev in list] [next in list] [prev in thread] [next in thread] 

List:       postgresql-general
Subject:    Re: [GENERAL] Migration problem - serial fields
From:       Brent Verner <brent () rcfile ! org>
Date:       2002-03-07 16:01:01
[Download RAW message or body]

[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

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/users-lounge/docs/faq.html
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic