From: | jian he <jian(dot)universality(at)gmail(dot)com> |
---|---|
To: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | clean up create|alter domain stmt incompatiable constraint error case and add regression test |
Date: | 2024-11-11 08:59:12 |
Message-ID: | CACJufxHHcpSkz1=AgW5bYo9VaoRjtPuUaDnZOHZbynOADjNS_A@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
hi.
https://coverage.postgresql.org/src/backend/commands/typecmds.c.gcov.html
show DefineDomain has poor coverage tests.
so I added a more extensive regression test.
also
create domain d_fail as int4 constraint cc GENERATED ALWAYS AS (2) STORED;
ERROR: unrecognized constraint subtype: 4
This kind of error message is not helpful. so I changed it to
ERROR: generated columns are not supported on domains
create domain d_int as int4;
ALTER DOMAIN d_int ADD constraint cc check(value > 1) no inherit not valid;
should fail.
so I made it fail.
typedef struct AlterDomainStmt
{
NodeTag type;
char subtype;
List *typeName; /* domain to work on */
char *name; /* column or constraint name to act on */
Node *def; /* definition of default or constraint */
DropBehavior behavior; /* RESTRICT or CASCADE for DROP cases */
bool missing_ok; /* skip error if missing? */
} AlterDomainStmt;
we only have one `Node *def; ` in AlterDomainStmt
unlike CreateDomainStmt, have `List *constraints;`
so I guess we have to allow the following ALTER DOMAIN queries.
even though the corresponding CREATE DOMAIN stmt would fail.
create domain d_int as int4;
ALTER DOMAIN d_int ADD constraint cc1 check(value > 1) INITIALLY IMMEDIATE; --ok
ALTER DOMAIN d_int ADD constraint cc2 check(value > 1) NOT DEFERRABLE; --ok
ALTER DOMAIN d_int ADD constraint cc3 check(value > 1) NOT DEFERRABLE
not valid; --ok
ALTER DOMAIN d_int ADD constraint cc4 check(value > 1) INITIALLY
IMMEDIATE not valid; --ok
looking at pg_constraint, for the above queries, column {condeferrable
| condeferred | convalidated} all set properly.
i didn't found a way to trigger
errmsg("exclusion constraints not possible for domains")));
Attachment | Content-Type | Size |
---|---|---|
v1-0001-add-more-CREATE-ALTER-DOMAIN-tests.patch | application/x-patch | 10.2 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Hayato Kuroda (Fujitsu) | 2024-11-11 09:49:19 | RE: Commit Timestamp and LSN Inversion issue |
Previous Message | Guillaume Lelarge | 2024-11-11 08:34:57 | Re: Add parallel columns for seq scan and index scan on pg_stat_all_tables and _indexes |