From: | Matheus de Oliveira <matioli(dot)matheus(at)gmail(dot)com> |
---|---|
To: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | [PATCH] Add support for ON UPDATE/DELETE actions on ALTER CONSTRAINT |
Date: | 2018-02-20 15:10:22 |
Message-ID: | CAJghg4K_U=KJg6K156kWm2YmOXZmeCzUzitmP4RH=BM4Xu+cWQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hi all.
I attached a patch to add support for changing ON UPDATE/DELETE actions of
a constraint using ALTER TABLE ... ALTER CONSTRAINT.
Besides that, there is a another change in this patch on current ALTER
CONSTRAINT about deferrability options. Previously, if the user did ALTER
CONSTRAINT without specifying an option on deferrable or initdeferred, it
was implied the default options, so this:
ALTER TABLE tbl
ALTER CONSTRAINT con_name;
Was equivalent to:
ALTER TABLE tbl
ALTER CONSTRAINT con_name NOT DEFERRABLE INITIALLY IMMEDIATE;
If I kept it that way, it means that changing only ON UPDATE or ON DELETE
would cause deferrability options to be changed to the default. Now, I keep
an information of which options has actually been changed, so only the
actual changes are persisted.
But there are two exceptions (which I think that make sense):
1. If the user does only `ALTER CONSTRAINT ... INITIALLY DEFERRED`, no
matter the previous value of deferrable, it will be set to true.
2. If the user does only `ALTER CONSTRAINT ... NOT DEFERRABLE`, no matter
the previous value of initdeferred, it will be set to false.
I have pondered to raise an exception in the above cases instead of forcing
deferrable/initdeferred to valid values, but since the same behavior
happens on ADD CONSTRAINT, I think this way is simpler.
Since I'm a newbie on PG source code, this patch seems to be a bit big for
me. So please, let me know what you think about it. Specially the change on
Constraint struct on parsenode.h (and support to it on copyfuncs.c and
outfuncs.c), I'm not 100% sure that is the best way to track if
deferrability options were changed.
Thanks a lot.
Regards,
--
Matheus de Oliveira
Attachment | Content-Type | Size |
---|---|---|
postgresql-alter-constraint.v1.patch | text/x-patch | 165.4 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Aleksander Alekseev | 2018-02-20 15:13:56 | Re: [PATCH] Add a few suppression rules for Valgrind |
Previous Message | Laurenz Albe | 2018-02-20 15:09:57 | Re: NEXT VALUE FOR sequence |