summaryrefslogtreecommitdiff
path: root/src/backend/commands
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2024-12-16 14:52:11 +0900
committerMichael Paquier <michael@paquier.xyz>2024-12-16 14:52:11 +0900
commit39240bcad56dc51a7896d04a1e066efcf988b58f (patch)
treee85b9529dd7f21273581e7b78cd868c4b648c38c /src/backend/commands
parent3ad8b840ce8b1d7279f2d0d5fb7d346c0a6a3e8d (diff)
Print out error position for CREATE DOMAIN
This is simply done by pushing down the ParseState available in ProcessUtility() to DefineDomain(), giving more information about the position of an error when running a CREATE DOMAIN query. Most of the queries impacted by this change have been added previously in 0172b4c9449e. Author: Kirill Reshke, Jian He Reviewed-by: Álvaro Herrera, Tom Lane, Michael Paquier Discussion: https://postgr.es/m/CALdSSPhqfvKbDwqJaY=yEePi_aq61GmMpW88i6ZH7CMG_2Z4Cg@mail.gmail.com
Diffstat (limited to 'src/backend/commands')
-rw-r--r--src/backend/commands/typecmds.c58
1 files changed, 34 insertions, 24 deletions
diff --git a/src/backend/commands/typecmds.c b/src/backend/commands/typecmds.c
index da591c0922b..61273139560 100644
--- a/src/backend/commands/typecmds.c
+++ b/src/backend/commands/typecmds.c
@@ -694,7 +694,7 @@ RemoveTypeById(Oid typeOid)
* Registers a new domain.
*/
ObjectAddress
-DefineDomain(CreateDomainStmt *stmt)
+DefineDomain(ParseState *pstate, CreateDomainStmt *stmt)
{
char *domainName;
char *domainArrayName;
@@ -761,7 +761,7 @@ DefineDomain(CreateDomainStmt *stmt)
/*
* Look up the base type.
*/
- typeTup = typenameType(NULL, stmt->typeName, &basetypeMod);
+ typeTup = typenameType(pstate, stmt->typeName, &basetypeMod);
baseType = (Form_pg_type) GETSTRUCT(typeTup);
basetypeoid = baseType->oid;
@@ -783,7 +783,8 @@ DefineDomain(CreateDomainStmt *stmt)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("\"%s\" is not a valid base type for a domain",
- TypeNameToString(stmt->typeName))));
+ TypeNameToString(stmt->typeName)),
+ parser_errposition(pstate, stmt->typeName->location)));
aclresult = object_aclcheck(TypeRelationId, basetypeoid, GetUserId(), ACL_USAGE);
if (aclresult != ACLCHECK_OK)
@@ -809,7 +810,8 @@ DefineDomain(CreateDomainStmt *stmt)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("collations are not supported by type %s",
- format_type_be(basetypeoid))));
+ format_type_be(basetypeoid)),
+ parser_errposition(pstate, stmt->typeName->location)));
/* passed by value */
byValue = baseType->typbyval;
@@ -879,18 +881,15 @@ DefineDomain(CreateDomainStmt *stmt)
*/
if (saw_default)
ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("multiple default expressions")));
+ errcode(ERRCODE_SYNTAX_ERROR),
+ errmsg("multiple default expressions"),
+ parser_errposition(pstate, constr->location));
saw_default = true;
if (constr->raw_expr)
{
- ParseState *pstate;
Node *defaultExpr;
- /* Create a dummy ParseState for transformExpr */
- pstate = make_parsestate(NULL);
-
/*
* Cook the constr->raw_expr into an expression. Note:
* name is strictly for error message
@@ -942,12 +941,14 @@ DefineDomain(CreateDomainStmt *stmt)
case CONSTR_NOTNULL:
if (nullDefined && !typNotNull)
ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("conflicting NULL/NOT NULL constraints")));
+ errcode(ERRCODE_SYNTAX_ERROR),
+ errmsg("conflicting NULL/NOT NULL constraints"),
+ parser_errposition(pstate, constr->location));
if (constr->is_no_inherit)
ereport(ERROR,
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
- errmsg("not-null constraints for domains cannot be marked NO INHERIT"));
+ errmsg("not-null constraints for domains cannot be marked NO INHERIT"),
+ parser_errposition(pstate, constr->location));
typNotNull = true;
nullDefined = true;
break;
@@ -955,8 +956,9 @@ DefineDomain(CreateDomainStmt *stmt)
case CONSTR_NULL:
if (nullDefined && typNotNull)
ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("conflicting NULL/NOT NULL constraints")));
+ errcode(ERRCODE_SYNTAX_ERROR),
+ errmsg("conflicting NULL/NOT NULL constraints"),
+ parser_errposition(pstate, constr->location));
typNotNull = false;
nullDefined = true;
break;
@@ -971,8 +973,10 @@ DefineDomain(CreateDomainStmt *stmt)
*/
if (constr->is_no_inherit)
ereport(ERROR,
- (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
- errmsg("check constraints for domains cannot be marked NO INHERIT")));
+ errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+ errmsg("check constraints for domains cannot be marked NO INHERIT"),
+ parser_errposition(pstate, constr->location));
+
break;
/*
@@ -980,26 +984,30 @@ DefineDomain(CreateDomainStmt *stmt)
*/
case CONSTR_UNIQUE:
ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("unique constraints not possible for domains")));
+ errcode(ERRCODE_SYNTAX_ERROR),
+ errmsg("unique constraints not possible for domains"),
+ parser_errposition(pstate, constr->location));
break;
case CONSTR_PRIMARY:
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("primary key constraints not possible for domains")));
+ errmsg("primary key constraints not possible for domains"),
+ parser_errposition(pstate, constr->location)));
break;
case CONSTR_EXCLUSION:
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("exclusion constraints not possible for domains")));
+ errmsg("exclusion constraints not possible for domains"),
+ parser_errposition(pstate, constr->location)));
break;
case CONSTR_FOREIGN:
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("foreign key constraints not possible for domains")));
+ errmsg("foreign key constraints not possible for domains"),
+ parser_errposition(pstate, constr->location)));
break;
case CONSTR_ATTR_DEFERRABLE:
@@ -1008,14 +1016,16 @@ DefineDomain(CreateDomainStmt *stmt)
case CONSTR_ATTR_IMMEDIATE:
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("specifying constraint deferrability not supported for domains")));
+ errmsg("specifying constraint deferrability not supported for domains"),
+ parser_errposition(pstate, constr->location)));
break;
case CONSTR_GENERATED:
case CONSTR_IDENTITY:
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("specifying GENERATED not supported for domains")));
+ errmsg("specifying GENERATED not supported for domains"),
+ parser_errposition(pstate, constr->location)));
break;
/* no default, to let compiler warn about missing case */