Sequence (related) Problem

Started by Ron St-Pierreover 23 years ago2 messagesgeneral
Jump to latest
#1Ron St-Pierre
rstpierre@syscor.com

I am migrating a DB from Access to postgreSQL and am making quite a few
changes to it including renaming tables, columns, sequences, etc.

I am renaming TBLOLD to TBLNEW and consequently need to rename the
sequence from TBLOLD_ID_SEQ to TBLNEW_ID_SEQ. I also want it to START at
a value just above TBLOLD's last value. To set the start value of the
new sequence I am trying:

CREATE SEQUENCE 'tblnew_id_seq' start nextval('tblold_id_deq')
increment 1 maxvalue 2147483647 minvalue 1 cache 1 ;
as well as many variations of the above (including using SELECT to get
the nextval).

Could someone please point me to a solution?

Thanks

--
Ron St.Pierre
Syscor R&D
tel: 250-361-1681
email: rstpierre@syscor.com

#2Neil Conway
neilc@samurai.com
In reply to: Ron St-Pierre (#1)
Re: Sequence (related) Problem

On Wed, 2002-11-27 at 16:38, Ron St.Pierre wrote:

To set the start value of the new sequence I am trying:

CREATE SEQUENCE 'tblnew_id_seq' start nextval('tblold_id_deq')
increment 1 maxvalue 2147483647 minvalue 1 cache 1 ;

Execute the CREATE SEQUENCE with the default start value, and then set
it to whatever you like using:

SELECT setval('my_seq', nextval('abc') + ...);

Cheers,

Neil
--
Neil Conway <neilc@samurai.com> || PGP Key ID: DB3C29FC