serial sequence problem with existing keys

Started by Randall Perryover 24 years ago3 messagesgeneral
Jump to latest
#1Randall Perry
rgp@systame.com

I've had to modify a parent table by recreating it (I substituted integer
foreign key values from lookup tables for text in 2 fields. As postgres
doesn't have a DROP COLUMN command I couldn't revise the table structure
without rebuilding it) .

It has a serial data type for the primary key. I'm importing the data back
in and need to keep the original primary key values, as they're used in
several child tables.

But, if I put in my own key values in a serial field the auto-increment
sequence uses the next number from where it left off, and not the max value,
and complains that it can't create a duplicate key.

Is there any way around this, or am I going to have to programmatically
increment the key and change serial to int?

--
Randy Perry
sysTame
Mac Consulting/Sales

phn 561.589.6449
mobile email help@systame.com

#2Stephan Szabo
sszabo@megazone23.bigpanda.com
In reply to: Randall Perry (#1)
Re: serial sequence problem with existing keys

On Wed, 31 Oct 2001, Randall Perry wrote:

I've had to modify a parent table by recreating it (I substituted integer
foreign key values from lookup tables for text in 2 fields. As postgres
doesn't have a DROP COLUMN command I couldn't revise the table structure
without rebuilding it) .

It has a serial data type for the primary key. I'm importing the data back
in and need to keep the original primary key values, as they're used in
several child tables.

But, if I put in my own key values in a serial field the auto-increment
sequence uses the next number from where it left off, and not the max value,
and complains that it can't create a duplicate key.

Is there any way around this, or am I going to have to programmatically
increment the key and change serial to int?

Check out setval('<sequence name>', <number>) to change the sequence's
current value.

#3Randall Perry
rgp@systame.com
In reply to: Stephan Szabo (#2)
Re: serial sequence problem with existing keys

Check out setval('<sequence name>', <number>) to change the sequence's
current value.

That done did it.

Thanks

--
Randy Perry
sysTame
Mac Consulting/Sales

phn 561.589.6449
mobile email help@systame.com