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

Commit a279462

Browse files
committed
Extend the parser location infrastructure to include a location field in
most node types used in expression trees (both before and after parse analysis). This allows us to place an error cursor in many situations where we formerly could not, because the information wasn't available beyond the very first level of parse analysis. There's a fair amount of work still to be done to persuade individual ereport() calls to actually include an error location, but this gets the initdb-forcing part of the work out of the way; and the situation is already markedly better than before for complaints about unimplementable implicit casts, such as CASE and UNION constructs with incompatible alternative data types. Per my proposal of a few days ago.
1 parent 6734182 commit a279462

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1289
-496
lines changed

src/backend/catalog/heap.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.338 2008/08/25 22:42:32 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.339 2008/08/28 23:09:45 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -2121,7 +2121,8 @@ cookDefault(ParseState *pstate,
21212121
expr = coerce_to_target_type(pstate, expr, type_id,
21222122
atttypid, atttypmod,
21232123
COERCION_ASSIGNMENT,
2124-
COERCE_IMPLICIT_CAST);
2124+
COERCE_IMPLICIT_CAST,
2125+
-1);
21252126
if (expr == NULL)
21262127
ereport(ERROR,
21272128
(errcode(ERRCODE_DATATYPE_MISMATCH),

src/backend/commands/prepare.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Copyright (c) 2002-2008, PostgreSQL Global Development Group
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.90 2008/08/25 22:42:32 tgl Exp $
13+
* $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.91 2008/08/28 23:09:45 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -353,7 +353,8 @@ EvaluateParams(PreparedStatement *pstmt, List *params,
353353
expr = coerce_to_target_type(pstate, expr, given_type_id,
354354
expected_type_id, -1,
355355
COERCION_ASSIGNMENT,
356-
COERCE_IMPLICIT_CAST);
356+
COERCE_IMPLICIT_CAST,
357+
-1);
357358

358359
if (expr == NULL)
359360
ereport(ERROR,

src/backend/commands/tablecmds.c

+7-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.263 2008/08/25 22:42:32 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.264 2008/08/28 23:09:45 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -3649,7 +3649,8 @@ ATExecAddColumn(AlteredTableInfo *tab, Relation rel,
36493649
typeOid,
36503650
typmod,
36513651
COERCION_ASSIGNMENT,
3652-
COERCE_IMPLICIT_CAST);
3652+
COERCE_IMPLICIT_CAST,
3653+
-1);
36533654
if (defval == NULL) /* should not happen */
36543655
elog(ERROR, "failed to coerce base type to domain");
36553656
}
@@ -5509,7 +5510,8 @@ ATPrepAlterColumnType(List **wqueue,
55095510
transform, exprType(transform),
55105511
targettype, targettypmod,
55115512
COERCION_ASSIGNMENT,
5512-
COERCE_IMPLICIT_CAST);
5513+
COERCE_IMPLICIT_CAST,
5514+
-1);
55135515
if (transform == NULL)
55145516
ereport(ERROR,
55155517
(errcode(ERRCODE_DATATYPE_MISMATCH),
@@ -5607,7 +5609,8 @@ ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel,
56075609
defaultexpr, exprType(defaultexpr),
56085610
targettype, targettypmod,
56095611
COERCION_ASSIGNMENT,
5610-
COERCE_IMPLICIT_CAST);
5612+
COERCE_IMPLICIT_CAST,
5613+
-1);
56115614
if (defaultexpr == NULL)
56125615
ereport(ERROR,
56135616
(errcode(ERRCODE_DATATYPE_MISMATCH),

src/backend/commands/typecmds.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.122 2008/07/31 16:27:16 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.123 2008/08/28 23:09:45 tgl Exp $
1212
*
1313
* DESCRIPTION
1414
* The "DefineFoo" routines take the parse tree and pick out the
@@ -2135,6 +2135,7 @@ domainAddConstraint(Oid domainOid, Oid domainNamespace, Oid baseTypeOid,
21352135
domVal = makeNode(CoerceToDomainValue);
21362136
domVal->typeId = baseTypeOid;
21372137
domVal->typeMod = typMod;
2138+
domVal->location = -1; /* will be set when/if used */
21382139

21392140
pstate->p_value_substitute = (Node *) domVal;
21402141

src/backend/nodes/copyfuncs.c

+41-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Portions Copyright (c) 1994, Regents of the University of California
1616
*
1717
* IDENTIFICATION
18-
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.401 2008/08/22 00:16:03 tgl Exp $
18+
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.402 2008/08/28 23:09:45 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -58,6 +58,10 @@
5858
memcpy(newnode->fldname, from->fldname, _size); \
5959
} while (0)
6060

61+
/* Copy a parse location field (for Copy, this is same as scalar case) */
62+
#define COPY_LOCATION_FIELD(fldname) \
63+
(newnode->fldname = from->fldname)
64+
6165

6266
/* ****************************************************************
6367
* plannodes.h copy functions
@@ -761,6 +765,7 @@ _copyVar(Var *from)
761765
COPY_SCALAR_FIELD(varlevelsup);
762766
COPY_SCALAR_FIELD(varnoold);
763767
COPY_SCALAR_FIELD(varoattno);
768+
COPY_LOCATION_FIELD(location);
764769

765770
return newnode;
766771
}
@@ -797,6 +802,7 @@ _copyConst(Const *from)
797802

798803
COPY_SCALAR_FIELD(constisnull);
799804
COPY_SCALAR_FIELD(constbyval);
805+
COPY_LOCATION_FIELD(location);
800806

801807
return newnode;
802808
}
@@ -813,6 +819,7 @@ _copyParam(Param *from)
813819
COPY_SCALAR_FIELD(paramid);
814820
COPY_SCALAR_FIELD(paramtype);
815821
COPY_SCALAR_FIELD(paramtypmod);
822+
COPY_LOCATION_FIELD(location);
816823

817824
return newnode;
818825
}
@@ -831,6 +838,7 @@ _copyAggref(Aggref *from)
831838
COPY_SCALAR_FIELD(agglevelsup);
832839
COPY_SCALAR_FIELD(aggstar);
833840
COPY_SCALAR_FIELD(aggdistinct);
841+
COPY_LOCATION_FIELD(location);
834842

835843
return newnode;
836844
}
@@ -867,6 +875,7 @@ _copyFuncExpr(FuncExpr *from)
867875
COPY_SCALAR_FIELD(funcretset);
868876
COPY_SCALAR_FIELD(funcformat);
869877
COPY_NODE_FIELD(args);
878+
COPY_LOCATION_FIELD(location);
870879

871880
return newnode;
872881
}
@@ -884,6 +893,7 @@ _copyOpExpr(OpExpr *from)
884893
COPY_SCALAR_FIELD(opresulttype);
885894
COPY_SCALAR_FIELD(opretset);
886895
COPY_NODE_FIELD(args);
896+
COPY_LOCATION_FIELD(location);
887897

888898
return newnode;
889899
}
@@ -901,6 +911,7 @@ _copyDistinctExpr(DistinctExpr *from)
901911
COPY_SCALAR_FIELD(opresulttype);
902912
COPY_SCALAR_FIELD(opretset);
903913
COPY_NODE_FIELD(args);
914+
COPY_LOCATION_FIELD(location);
904915

905916
return newnode;
906917
}
@@ -917,6 +928,7 @@ _copyScalarArrayOpExpr(ScalarArrayOpExpr *from)
917928
COPY_SCALAR_FIELD(opfuncid);
918929
COPY_SCALAR_FIELD(useOr);
919930
COPY_NODE_FIELD(args);
931+
COPY_LOCATION_FIELD(location);
920932

921933
return newnode;
922934
}
@@ -931,6 +943,7 @@ _copyBoolExpr(BoolExpr *from)
931943

932944
COPY_SCALAR_FIELD(boolop);
933945
COPY_NODE_FIELD(args);
946+
COPY_LOCATION_FIELD(location);
934947

935948
return newnode;
936949
}
@@ -947,6 +960,7 @@ _copySubLink(SubLink *from)
947960
COPY_NODE_FIELD(testexpr);
948961
COPY_NODE_FIELD(operName);
949962
COPY_NODE_FIELD(subselect);
963+
COPY_LOCATION_FIELD(location);
950964

951965
return newnode;
952966
}
@@ -1032,6 +1046,7 @@ _copyRelabelType(RelabelType *from)
10321046
COPY_SCALAR_FIELD(resulttype);
10331047
COPY_SCALAR_FIELD(resulttypmod);
10341048
COPY_SCALAR_FIELD(relabelformat);
1049+
COPY_LOCATION_FIELD(location);
10351050

10361051
return newnode;
10371052
}
@@ -1047,6 +1062,7 @@ _copyCoerceViaIO(CoerceViaIO *from)
10471062
COPY_NODE_FIELD(arg);
10481063
COPY_SCALAR_FIELD(resulttype);
10491064
COPY_SCALAR_FIELD(coerceformat);
1065+
COPY_LOCATION_FIELD(location);
10501066

10511067
return newnode;
10521068
}
@@ -1065,6 +1081,7 @@ _copyArrayCoerceExpr(ArrayCoerceExpr *from)
10651081
COPY_SCALAR_FIELD(resulttypmod);
10661082
COPY_SCALAR_FIELD(isExplicit);
10671083
COPY_SCALAR_FIELD(coerceformat);
1084+
COPY_LOCATION_FIELD(location);
10681085

10691086
return newnode;
10701087
}
@@ -1080,6 +1097,7 @@ _copyConvertRowtypeExpr(ConvertRowtypeExpr *from)
10801097
COPY_NODE_FIELD(arg);
10811098
COPY_SCALAR_FIELD(resulttype);
10821099
COPY_SCALAR_FIELD(convertformat);
1100+
COPY_LOCATION_FIELD(location);
10831101

10841102
return newnode;
10851103
}
@@ -1096,6 +1114,7 @@ _copyCaseExpr(CaseExpr *from)
10961114
COPY_NODE_FIELD(arg);
10971115
COPY_NODE_FIELD(args);
10981116
COPY_NODE_FIELD(defresult);
1117+
COPY_LOCATION_FIELD(location);
10991118

11001119
return newnode;
11011120
}
@@ -1110,6 +1129,7 @@ _copyCaseWhen(CaseWhen *from)
11101129

11111130
COPY_NODE_FIELD(expr);
11121131
COPY_NODE_FIELD(result);
1132+
COPY_LOCATION_FIELD(location);
11131133

11141134
return newnode;
11151135
}
@@ -1140,6 +1160,7 @@ _copyArrayExpr(ArrayExpr *from)
11401160
COPY_SCALAR_FIELD(element_typeid);
11411161
COPY_NODE_FIELD(elements);
11421162
COPY_SCALAR_FIELD(multidims);
1163+
COPY_LOCATION_FIELD(location);
11431164

11441165
return newnode;
11451166
}
@@ -1155,6 +1176,7 @@ _copyRowExpr(RowExpr *from)
11551176
COPY_NODE_FIELD(args);
11561177
COPY_SCALAR_FIELD(row_typeid);
11571178
COPY_SCALAR_FIELD(row_format);
1179+
COPY_LOCATION_FIELD(location);
11581180

11591181
return newnode;
11601182
}
@@ -1186,6 +1208,7 @@ _copyCoalesceExpr(CoalesceExpr *from)
11861208

11871209
COPY_SCALAR_FIELD(coalescetype);
11881210
COPY_NODE_FIELD(args);
1211+
COPY_LOCATION_FIELD(location);
11891212

11901213
return newnode;
11911214
}
@@ -1201,6 +1224,7 @@ _copyMinMaxExpr(MinMaxExpr *from)
12011224
COPY_SCALAR_FIELD(minmaxtype);
12021225
COPY_SCALAR_FIELD(op);
12031226
COPY_NODE_FIELD(args);
1227+
COPY_LOCATION_FIELD(location);
12041228

12051229
return newnode;
12061230
}
@@ -1221,6 +1245,7 @@ _copyXmlExpr(XmlExpr *from)
12211245
COPY_SCALAR_FIELD(xmloption);
12221246
COPY_SCALAR_FIELD(type);
12231247
COPY_SCALAR_FIELD(typmod);
1248+
COPY_LOCATION_FIELD(location);
12241249

12251250
return newnode;
12261251
}
@@ -1238,6 +1263,7 @@ _copyNullIfExpr(NullIfExpr *from)
12381263
COPY_SCALAR_FIELD(opresulttype);
12391264
COPY_SCALAR_FIELD(opretset);
12401265
COPY_NODE_FIELD(args);
1266+
COPY_LOCATION_FIELD(location);
12411267

12421268
return newnode;
12431269
}
@@ -1282,6 +1308,7 @@ _copyCoerceToDomain(CoerceToDomain *from)
12821308
COPY_SCALAR_FIELD(resulttype);
12831309
COPY_SCALAR_FIELD(resulttypmod);
12841310
COPY_SCALAR_FIELD(coercionformat);
1311+
COPY_LOCATION_FIELD(location);
12851312

12861313
return newnode;
12871314
}
@@ -1296,6 +1323,7 @@ _copyCoerceToDomainValue(CoerceToDomainValue *from)
12961323

12971324
COPY_SCALAR_FIELD(typeId);
12981325
COPY_SCALAR_FIELD(typeMod);
1326+
COPY_LOCATION_FIELD(location);
12991327

13001328
return newnode;
13011329
}
@@ -1310,6 +1338,7 @@ _copySetToDefault(SetToDefault *from)
13101338

13111339
COPY_SCALAR_FIELD(typeId);
13121340
COPY_SCALAR_FIELD(typeMod);
1341+
COPY_LOCATION_FIELD(location);
13131342

13141343
return newnode;
13151344
}
@@ -1595,7 +1624,7 @@ _copyAExpr(A_Expr *from)
15951624
COPY_NODE_FIELD(name);
15961625
COPY_NODE_FIELD(lexpr);
15971626
COPY_NODE_FIELD(rexpr);
1598-
COPY_SCALAR_FIELD(location);
1627+
COPY_LOCATION_FIELD(location);
15991628

16001629
return newnode;
16011630
}
@@ -1606,7 +1635,7 @@ _copyColumnRef(ColumnRef *from)
16061635
ColumnRef *newnode = makeNode(ColumnRef);
16071636

16081637
COPY_NODE_FIELD(fields);
1609-
COPY_SCALAR_FIELD(location);
1638+
COPY_LOCATION_FIELD(location);
16101639

16111640
return newnode;
16121641
}
@@ -1617,6 +1646,7 @@ _copyParamRef(ParamRef *from)
16171646
ParamRef *newnode = makeNode(ParamRef);
16181647

16191648
COPY_SCALAR_FIELD(number);
1649+
COPY_LOCATION_FIELD(location);
16201650

16211651
return newnode;
16221652
}
@@ -1647,6 +1677,8 @@ _copyAConst(A_Const *from)
16471677
break;
16481678
}
16491679

1680+
COPY_LOCATION_FIELD(location);
1681+
16501682
return newnode;
16511683
}
16521684

@@ -1660,7 +1692,7 @@ _copyFuncCall(FuncCall *from)
16601692
COPY_SCALAR_FIELD(agg_star);
16611693
COPY_SCALAR_FIELD(agg_distinct);
16621694
COPY_SCALAR_FIELD(func_variadic);
1663-
COPY_SCALAR_FIELD(location);
1695+
COPY_LOCATION_FIELD(location);
16641696

16651697
return newnode;
16661698
}
@@ -1693,6 +1725,7 @@ _copyA_ArrayExpr(A_ArrayExpr *from)
16931725
A_ArrayExpr *newnode = makeNode(A_ArrayExpr);
16941726

16951727
COPY_NODE_FIELD(elements);
1728+
COPY_LOCATION_FIELD(location);
16961729

16971730
return newnode;
16981731
}
@@ -1705,7 +1738,7 @@ _copyResTarget(ResTarget *from)
17051738
COPY_STRING_FIELD(name);
17061739
COPY_NODE_FIELD(indirection);
17071740
COPY_NODE_FIELD(val);
1708-
COPY_SCALAR_FIELD(location);
1741+
COPY_LOCATION_FIELD(location);
17091742

17101743
return newnode;
17111744
}
@@ -1722,7 +1755,7 @@ _copyTypeName(TypeName *from)
17221755
COPY_NODE_FIELD(typmods);
17231756
COPY_SCALAR_FIELD(typemod);
17241757
COPY_NODE_FIELD(arrayBounds);
1725-
COPY_SCALAR_FIELD(location);
1758+
COPY_LOCATION_FIELD(location);
17261759

17271760
return newnode;
17281761
}
@@ -1770,6 +1803,7 @@ _copyTypeCast(TypeCast *from)
17701803

17711804
COPY_NODE_FIELD(arg);
17721805
COPY_NODE_FIELD(typename);
1806+
COPY_LOCATION_FIELD(location);
17731807

17741808
return newnode;
17751809
}
@@ -1852,6 +1886,7 @@ _copyXmlSerialize(XmlSerialize *from)
18521886
COPY_SCALAR_FIELD(xmloption);
18531887
COPY_NODE_FIELD(expr);
18541888
COPY_NODE_FIELD(typename);
1889+
COPY_LOCATION_FIELD(location);
18551890

18561891
return newnode;
18571892
}

0 commit comments

Comments
 (0)