From: | Thomas Munro <munro(at)ip9(dot)org> |
---|---|
To: | pgsql-hackers(at)postgresql(dot)org |
Subject: | WIP -- renaming implicit sequences |
Date: | 2012-01-12 00:18:01 |
Message-ID: | CADLWmXUV4LbLhMZL8rYMhCy72aZZLB5BSARPQVgoX0BrxA0FFg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hi,
Here is an unfinished patch to implement something which appears on
the TODO list under ALTER: automatic renaming of sequences created
with serial when the table and column names change. I've often wanted
this feature and it seemed like a good starter project. I'd be
grateful for any feedback and advice on how I could get it into
acceptable shape. Example:
hack=# create table foo (id serial primary key);
NOTICE: CREATE TABLE will create implicit sequence "foo_id_seq" for
serial column "foo.id"
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index
"foo_pkey" for table "foo"
CREATE TABLE
hack=# alter table foo rename to bar;
NOTICE: ALTER TABLE will rename implicit sequence "foo_id_seq" to "bar_id_seq"
ALTER TABLE
hack=# alter table bar rename id to snacks;
NOTICE: ALTER TABLE will rename implicit sequence "bar_id_seq" to
"bar_snacks_seq"
ALTER TABLE
Sequences are considered to be renameable if they are owned by the
table, and have a name conforming to the name pattern used by CREATE
TABLE (table_column_seq with optional trailing numbers). If you've
manually renamed a SEQUENCE so that it doesn't conform, it won't touch
it. If you've created a SEQUENCE and declared it to be OWNED BY the
table, then it will be renamed only if it happens to conform.
I'm not sure what to do about permissions. I guess it should silently
skip renaming sequences if the user doesn't have appropriate
privileges.
Useful? Why would anyone not want this behaviour? Have I used
inappropriate locking levels? What should I read to understand the
rules of locking? Have I failed to handle errors? Have I made memory
ownership mistakes?
Thanks!
Thomas Munro
Attachment | Content-Type | Size |
---|---|---|
rename-implicit-sequences-1.patch | text/x-patch | 6.4 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2012-01-12 00:43:02 | Re: Remembering bug #6123 |
Previous Message | Tom Lane | 2012-01-12 00:09:30 | Re: [WIP] Double-write with Fast Checksums |