Proposed patch for sequence-renaming problems

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-patches(at)postgreSQL(dot)org
Subject: Proposed patch for sequence-renaming problems
Date: 2005-09-27 22:46:55
Message-ID: 29471.1127861215@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

Attached is a fully-worked-out patch to make SERIAL column default
expressions refer to the target sequence with a "regclass" literal
instead of a "text" literal. Since the regclass literal is actually
just an OID, it is impervious to renamings and schema changes of
the target sequence. This fixes the long-standing hazard of renaming
a serial column's sequence, as well as the recently added hazard of
renaming the schema the sequence is in; and it lets us get rid of a
very klugy solution in ALTER TABLE SET SCHEMA.

I've arranged for stored regclass literals to create dependencies on
the referenced relation, which provides useful improvements even for
handwritten defaults: given

create sequence myseq;
create table foo (f1 int default nextval('myseq'::regclass));

the system will not allow myseq to be dropped while the default
expression remains. (This also ensures that pg_dump will emit the
sequence before the table.)

The patch also fixes a couple of places where code was still looking
at the deprecated pg_attrdef.adsrc column, instead of reverse-compiling
pg_attrdef.adbin. This ensures that psql's \d command shows the
up-to-date form of a column default. (That should have happened quite
some time ago; not sure why it was overlooked.)

I propose applying this to fix the open issue that ALTER SCHEMA RENAME
breaks serial columns. Comments, objections?

regards, tom lane

Attachment Content-Type Size
seq-regclass.patch.gz application/octet-stream 9.0 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2005-09-27 22:53:13 Re: \d on database with a lot of tables is slow
Previous Message Jim C. Nasby 2005-09-27 22:46:26 Re: \d on database with a lot of tables is slow

Browse pgsql-patches by date

  From Date Subject
Next Message Bruce Momjian 2005-09-27 23:44:20 Re: Proposed patch for sequence-renaming problems
Previous Message Martijn van Oosterhout 2005-09-27 17:54:44 Re: [HACKERS] \x output blowing up