Re: Proposed patch for sequence-renaming problems

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-patches(at)postgresql(dot)org
Subject: Re: Proposed patch for sequence-renaming problems
Date: 2005-09-27 23:44:20
Message-ID: 200509272344.j8RNiKY07882@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches


I looked over the patch, and while it does fix the problem for SERIAL, I
am concerned about expecting users to user ::regclass in normal usage,
and I am concerned about adding something we will have to support in the
future when we come up with a better solution. Why is regclass not
being used automatically?

---------------------------------------------------------------------------

Tom Lane wrote:
> 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
>

Content-Description: seq-regclass.patch.gz

[ Type application/octet-stream treated as attachment, skipping... ]

>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: don't forget to increase your free space map settings

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Marc G. Fournier 2005-09-27 23:49:53 Re: Open items list for 8.1
Previous Message Tom Lane 2005-09-27 23:19:11 Re: Open items list for 8.1

Browse pgsql-patches by date

  From Date Subject
Next Message Kris Jurka 2005-09-28 01:18:15 high values for client_min_messages
Previous Message Tom Lane 2005-09-27 22:46:55 Proposed patch for sequence-renaming problems