1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-26 12:21:12 +03:00

Fix handling of CREATE DOMAIN with GENERATED constraint syntax

Stuff like

    CREATE DOMAIN foo AS int CONSTRAINT cc GENERATED ALWAYS AS (2) STORED

is not supported for domains, but the parser allows it, because it's
the same syntax as for table constraints.  But CreateDomain() did not
explicitly handle all ConstrType values, so the above would get an
internal error like

    ERROR:  unrecognized constraint subtype: 4

Fix that by providing a user-facing error message for all ConstrType
values.  Also, remove the switch default case, so future additions to
ConstrType are caught.

Reported-by: Jian He <jian.universality@gmail.com>
Discussion: https://www.postgresql.org/message-id/CACJufxF8fmM=Dbm4pDFuV_nKGz2-No0k4YifhrF3-rjXTWJM3w@mail.gmail.com
This commit is contained in:
Peter Eisentraut
2024-12-03 14:32:45 +01:00
parent 1acf10549e
commit 84a67725cd

View File

@ -1011,10 +1011,14 @@ DefineDomain(CreateDomainStmt *stmt)
errmsg("specifying constraint deferrability not supported for domains"))); errmsg("specifying constraint deferrability not supported for domains")));
break; break;
default: case CONSTR_GENERATED:
elog(ERROR, "unrecognized constraint subtype: %d", case CONSTR_IDENTITY:
(int) constr->contype); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("specifying GENERATED not supported for domains")));
break; break;
/* no default, to let compiler warn about missing case */
} }
} }