Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 39240bc

Browse files
committed
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 0172b4c. 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
1 parent 3ad8b84 commit 39240bc

File tree

8 files changed

+70
-26
lines changed

8 files changed

+70
-26
lines changed

src/backend/commands/typecmds.c

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ RemoveTypeById(Oid typeOid)
694694
* Registers a new domain.
695695
*/
696696
ObjectAddress
697-
DefineDomain(CreateDomainStmt *stmt)
697+
DefineDomain(ParseState *pstate, CreateDomainStmt *stmt)
698698
{
699699
char *domainName;
700700
char *domainArrayName;
@@ -761,7 +761,7 @@ DefineDomain(CreateDomainStmt *stmt)
761761
/*
762762
* Look up the base type.
763763
*/
764-
typeTup = typenameType(NULL, stmt->typeName, &basetypeMod);
764+
typeTup = typenameType(pstate, stmt->typeName, &basetypeMod);
765765
baseType = (Form_pg_type) GETSTRUCT(typeTup);
766766
basetypeoid = baseType->oid;
767767

@@ -783,7 +783,8 @@ DefineDomain(CreateDomainStmt *stmt)
783783
ereport(ERROR,
784784
(errcode(ERRCODE_DATATYPE_MISMATCH),
785785
errmsg("\"%s\" is not a valid base type for a domain",
786-
TypeNameToString(stmt->typeName))));
786+
TypeNameToString(stmt->typeName)),
787+
parser_errposition(pstate, stmt->typeName->location)));
787788

788789
aclresult = object_aclcheck(TypeRelationId, basetypeoid, GetUserId(), ACL_USAGE);
789790
if (aclresult != ACLCHECK_OK)
@@ -809,7 +810,8 @@ DefineDomain(CreateDomainStmt *stmt)
809810
ereport(ERROR,
810811
(errcode(ERRCODE_DATATYPE_MISMATCH),
811812
errmsg("collations are not supported by type %s",
812-
format_type_be(basetypeoid))));
813+
format_type_be(basetypeoid)),
814+
parser_errposition(pstate, stmt->typeName->location)));
813815

814816
/* passed by value */
815817
byValue = baseType->typbyval;
@@ -879,18 +881,15 @@ DefineDomain(CreateDomainStmt *stmt)
879881
*/
880882
if (saw_default)
881883
ereport(ERROR,
882-
(errcode(ERRCODE_SYNTAX_ERROR),
883-
errmsg("multiple default expressions")));
884+
errcode(ERRCODE_SYNTAX_ERROR),
885+
errmsg("multiple default expressions"),
886+
parser_errposition(pstate, constr->location));
884887
saw_default = true;
885888

886889
if (constr->raw_expr)
887890
{
888-
ParseState *pstate;
889891
Node *defaultExpr;
890892

891-
/* Create a dummy ParseState for transformExpr */
892-
pstate = make_parsestate(NULL);
893-
894893
/*
895894
* Cook the constr->raw_expr into an expression. Note:
896895
* name is strictly for error message
@@ -942,21 +941,24 @@ DefineDomain(CreateDomainStmt *stmt)
942941
case CONSTR_NOTNULL:
943942
if (nullDefined && !typNotNull)
944943
ereport(ERROR,
945-
(errcode(ERRCODE_SYNTAX_ERROR),
946-
errmsg("conflicting NULL/NOT NULL constraints")));
944+
errcode(ERRCODE_SYNTAX_ERROR),
945+
errmsg("conflicting NULL/NOT NULL constraints"),
946+
parser_errposition(pstate, constr->location));
947947
if (constr->is_no_inherit)
948948
ereport(ERROR,
949949
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
950-
errmsg("not-null constraints for domains cannot be marked NO INHERIT"));
950+
errmsg("not-null constraints for domains cannot be marked NO INHERIT"),
951+
parser_errposition(pstate, constr->location));
951952
typNotNull = true;
952953
nullDefined = true;
953954
break;
954955

955956
case CONSTR_NULL:
956957
if (nullDefined && typNotNull)
957958
ereport(ERROR,
958-
(errcode(ERRCODE_SYNTAX_ERROR),
959-
errmsg("conflicting NULL/NOT NULL constraints")));
959+
errcode(ERRCODE_SYNTAX_ERROR),
960+
errmsg("conflicting NULL/NOT NULL constraints"),
961+
parser_errposition(pstate, constr->location));
960962
typNotNull = false;
961963
nullDefined = true;
962964
break;
@@ -971,35 +973,41 @@ DefineDomain(CreateDomainStmt *stmt)
971973
*/
972974
if (constr->is_no_inherit)
973975
ereport(ERROR,
974-
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
975-
errmsg("check constraints for domains cannot be marked NO INHERIT")));
976+
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
977+
errmsg("check constraints for domains cannot be marked NO INHERIT"),
978+
parser_errposition(pstate, constr->location));
979+
976980
break;
977981

978982
/*
979983
* All else are error cases
980984
*/
981985
case CONSTR_UNIQUE:
982986
ereport(ERROR,
983-
(errcode(ERRCODE_SYNTAX_ERROR),
984-
errmsg("unique constraints not possible for domains")));
987+
errcode(ERRCODE_SYNTAX_ERROR),
988+
errmsg("unique constraints not possible for domains"),
989+
parser_errposition(pstate, constr->location));
985990
break;
986991

987992
case CONSTR_PRIMARY:
988993
ereport(ERROR,
989994
(errcode(ERRCODE_SYNTAX_ERROR),
990-
errmsg("primary key constraints not possible for domains")));
995+
errmsg("primary key constraints not possible for domains"),
996+
parser_errposition(pstate, constr->location)));
991997
break;
992998

993999
case CONSTR_EXCLUSION:
9941000
ereport(ERROR,
9951001
(errcode(ERRCODE_SYNTAX_ERROR),
996-
errmsg("exclusion constraints not possible for domains")));
1002+
errmsg("exclusion constraints not possible for domains"),
1003+
parser_errposition(pstate, constr->location)));
9971004
break;
9981005

9991006
case CONSTR_FOREIGN:
10001007
ereport(ERROR,
10011008
(errcode(ERRCODE_SYNTAX_ERROR),
1002-
errmsg("foreign key constraints not possible for domains")));
1009+
errmsg("foreign key constraints not possible for domains"),
1010+
parser_errposition(pstate, constr->location)));
10031011
break;
10041012

10051013
case CONSTR_ATTR_DEFERRABLE:
@@ -1008,14 +1016,16 @@ DefineDomain(CreateDomainStmt *stmt)
10081016
case CONSTR_ATTR_IMMEDIATE:
10091017
ereport(ERROR,
10101018
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1011-
errmsg("specifying constraint deferrability not supported for domains")));
1019+
errmsg("specifying constraint deferrability not supported for domains"),
1020+
parser_errposition(pstate, constr->location)));
10121021
break;
10131022

10141023
case CONSTR_GENERATED:
10151024
case CONSTR_IDENTITY:
10161025
ereport(ERROR,
10171026
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1018-
errmsg("specifying GENERATED not supported for domains")));
1027+
errmsg("specifying GENERATED not supported for domains"),
1028+
parser_errposition(pstate, constr->location)));
10191029
break;
10201030

10211031
/* no default, to let compiler warn about missing case */

src/backend/tcop/utility.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1712,7 +1712,7 @@ ProcessUtilitySlow(ParseState *pstate,
17121712
break;
17131713

17141714
case T_CreateDomainStmt:
1715-
address = DefineDomain((CreateDomainStmt *) parsetree);
1715+
address = DefineDomain(pstate, (CreateDomainStmt *) parsetree);
17161716
break;
17171717

17181718
case T_CreateConversionStmt:

src/include/commands/typecmds.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
extern ObjectAddress DefineType(ParseState *pstate, List *names, List *parameters);
2525
extern void RemoveTypeById(Oid typeOid);
26-
extern ObjectAddress DefineDomain(CreateDomainStmt *stmt);
26+
extern ObjectAddress DefineDomain(ParseState *pstate, CreateDomainStmt *stmt);
2727
extern ObjectAddress DefineEnum(CreateEnumStmt *stmt);
2828
extern ObjectAddress DefineRange(ParseState *pstate, CreateRangeStmt *stmt);
2929
extern ObjectAddress AlterEnum(AlterEnumStmt *stmt);

src/test/regress/expected/collate.icu.utf8.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ LINE 1: ...* FROM collate_test1 WHERE b COLLATE "C" >= 'bbc' COLLATE "e...
120120
CREATE DOMAIN testdomain_sv AS text COLLATE "sv-x-icu";
121121
CREATE DOMAIN testdomain_i AS int COLLATE "sv-x-icu"; -- fails
122122
ERROR: collations are not supported by type integer
123+
LINE 1: CREATE DOMAIN testdomain_i AS int COLLATE "sv-x-icu";
124+
^
123125
CREATE TABLE collate_test4 (
124126
a int,
125127
b testdomain_sv

src/test/regress/expected/collate.linux.utf8.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ LINE 1: ...* FROM collate_test1 WHERE b COLLATE "C" >= 'bbc' COLLATE "e...
122122
CREATE DOMAIN testdomain_sv AS text COLLATE "sv_SE";
123123
CREATE DOMAIN testdomain_i AS int COLLATE "sv_SE"; -- fails
124124
ERROR: collations are not supported by type integer
125+
LINE 1: CREATE DOMAIN testdomain_i AS int COLLATE "sv_SE";
126+
^
125127
CREATE TABLE collate_test4 (
126128
a int,
127129
b testdomain_sv

src/test/regress/expected/collate.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ LINE 1: ...* FROM collate_test1 WHERE b COLLATE "C" >= 'bbc' COLLATE "P...
7373
CREATE DOMAIN testdomain_p AS text COLLATE "POSIX";
7474
CREATE DOMAIN testdomain_i AS int COLLATE "POSIX"; -- fail
7575
ERROR: collations are not supported by type integer
76+
LINE 1: CREATE DOMAIN testdomain_i AS int COLLATE "POSIX";
77+
^
7678
CREATE TABLE collate_test4 (
7779
a int,
7880
b testdomain_p

src/test/regress/expected/collate.windows.win1252.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ LINE 1: ...* FROM collate_test1 WHERE b COLLATE "C" >= 'bbc' COLLATE "e...
124124
CREATE DOMAIN testdomain_sv AS text COLLATE "sv_SE";
125125
CREATE DOMAIN testdomain_i AS int COLLATE "sv_SE"; -- fails
126126
ERROR: collations are not supported by type integer
127+
LINE 1: CREATE DOMAIN testdomain_i AS int COLLATE "sv_SE";
128+
^
127129
CREATE TABLE collate_test4 (
128130
a int,
129131
b testdomain_sv

src/test/regress/expected/domain.out

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,56 @@ ERROR: type "domaindroptest" does not exist
1818
-- some error cases
1919
create domain d_fail as no_such_type;
2020
ERROR: type "no_such_type" does not exist
21+
LINE 1: create domain d_fail as no_such_type;
22+
^
2123
create domain d_fail as int constraint cc REFERENCES this_table_not_exists(i);
2224
ERROR: foreign key constraints not possible for domains
25+
LINE 1: create domain d_fail as int constraint cc REFERENCES this_ta...
26+
^
2327
create domain d_fail as int4 not null no inherit;
2428
ERROR: not-null constraints for domains cannot be marked NO INHERIT
29+
LINE 1: create domain d_fail as int4 not null no inherit;
30+
^
2531
create domain d_fail as int4 not null null;
2632
ERROR: conflicting NULL/NOT NULL constraints
33+
LINE 1: create domain d_fail as int4 not null null;
34+
^
2735
create domain d_fail as int4 not null default 3 default 3;
2836
ERROR: multiple default expressions
37+
LINE 1: create domain d_fail as int4 not null default 3 default 3;
38+
^
2939
create domain d_fail int4 DEFAULT 3 + 'h';
3040
ERROR: invalid input syntax for type integer: "h"
41+
LINE 1: create domain d_fail int4 DEFAULT 3 + 'h';
42+
^
3143
create domain d_fail int4 collate "C";
3244
ERROR: collations are not supported by type integer
45+
LINE 1: create domain d_fail int4 collate "C";
46+
^
3347
create domain d_fail as anyelement;
3448
ERROR: "anyelement" is not a valid base type for a domain
49+
LINE 1: create domain d_fail as anyelement;
50+
^
3551
create domain d_fail as int4 unique;
3652
ERROR: unique constraints not possible for domains
53+
LINE 1: create domain d_fail as int4 unique;
54+
^
3755
create domain d_fail as int4 PRIMARY key;
3856
ERROR: primary key constraints not possible for domains
57+
LINE 1: create domain d_fail as int4 PRIMARY key;
58+
^
3959
create domain d_fail as int4 constraint cc generated by default as identity;
4060
ERROR: specifying GENERATED not supported for domains
61+
LINE 1: create domain d_fail as int4 constraint cc generated by defa...
62+
^
4163
create domain d_fail as int4 constraint cc check (values > 1) no inherit;
4264
ERROR: check constraints for domains cannot be marked NO INHERIT
65+
LINE 1: create domain d_fail as int4 constraint cc check (values > 1...
66+
^
4367
create domain d_fail as int4 constraint cc check (values > 1) deferrable;
4468
ERROR: specifying constraint deferrability not supported for domains
69+
LINE 1: ...n d_fail as int4 constraint cc check (values > 1) deferrable...
70+
^
4571
-- Test domain input.
4672
-- Note: the point of checking both INSERT and COPY FROM is that INSERT
4773
-- exercises CoerceToDomain while COPY exercises domain_in.

0 commit comments

Comments
 (0)