renaming sequences ?

Started by Jonathan Vanascoalmost 18 years ago2 messagesgeneral
Jump to latest
#1Jonathan Vanasco
postgres@2xlp.com

What is the correct way to rename a sequence?

I keep running into this bug:
http://archives.postgresql.org/pgsql-bugs/2007-09/msg00092.php

Where "ALTER TABLE/SEQUENCE RENAME TO ____" will rename the sequence,
but the 'sequence_name' attribute in 'select * from sequence' and (i
believe) the pg catalog info will keep the original name

this creates an issue with most ORM software under python, perl, php
which will pull the old sequence name.

the 'fix' i found is to just dump , drop, create and reload the
database -- which works perfect on small databases. but i'm left
wondering what the correct fix is for medium/larger databases.

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Jonathan Vanasco (#1)
Re: renaming sequences ?

Jonathan Vanasco <postgres@2xlp.com> writes:

I keep running into this bug:
http://archives.postgresql.org/pgsql-bugs/2007-09/msg00092.php

Where "ALTER TABLE/SEQUENCE RENAME TO ____" will rename the sequence,
but the 'sequence_name' attribute in 'select * from sequence' and (i
believe) the pg catalog info will keep the original name

this creates an issue with most ORM software under python, perl, php
which will pull the old sequence name.

The short answer is that any such software is broken and should be
fixed. The sequence_name in a sequence is a historical artifact and
can't be relied on, for exactly the reason that it doesn't update
during a rename. It's more likely that we'd remove the field than
that we'd fix this behavior --- it's not readily fixable because
there's no way to do transactional updates on the fields of a sequence.

regards, tom lane