Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit20ab467

Browse files
committed
Improve parser so that we can show an error cursor position for errors
during parse analysis, not only errors detected in the flex/bison stages.This is per my earlier proposal. This commit includes all the basicinfrastructure, but locations are only tracked and reported for errorsinvolving column references, function calls, and operators. More couldbe done later but this seems like a good set to start with. I've alsomoved the ReportSyntaxErrorPosition logic out of psql and into libpq,which should make it available to more people --- even within psql thisis an improvement because warnings weren't handled by ReportSyntaxErrorPosition.
1 parent48fb696 commit20ab467

File tree

80 files changed

+1348
-998
lines changed

Some content is hidden

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

80 files changed

+1348
-998
lines changed

‎contrib/earthdistance/expected/earthdistance.out

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,9 @@ SELECT earth_box(ll_to_earth(90,180),
881881
--
882882
SELECT is_point(ll_to_earth(0,0));
883883
ERROR: function is_point(earth) does not exist
884-
HINT: No function matches the given name and argument types. You may need to add explicit typecasts.
884+
LINE 1: SELECT is_point(ll_to_earth(0,0));
885+
^
886+
HINT: No function matches the given name and argument types. You may need to add explicit type casts.
885887
SELECT cube_dim(ll_to_earth(0,0)) <= 3;
886888
?column?
887889
----------
@@ -897,7 +899,9 @@ SELECT abs(cube_distance(ll_to_earth(0,0), '(0)'::cube) / earth() - 1) <
897899

898900
SELECT is_point(ll_to_earth(30,60));
899901
ERROR: function is_point(earth) does not exist
900-
HINT: No function matches the given name and argument types. You may need to add explicit typecasts.
902+
LINE 1: SELECT is_point(ll_to_earth(30,60));
903+
^
904+
HINT: No function matches the given name and argument types. You may need to add explicit type casts.
901905
SELECT cube_dim(ll_to_earth(30,60)) <= 3;
902906
?column?
903907
----------
@@ -913,7 +917,9 @@ SELECT abs(cube_distance(ll_to_earth(30,60), '(0)'::cube) / earth() - 1) <
913917

914918
SELECT is_point(ll_to_earth(60,90));
915919
ERROR: function is_point(earth) does not exist
916-
HINT: No function matches the given name and argument types. You may need to add explicit typecasts.
920+
LINE 1: SELECT is_point(ll_to_earth(60,90));
921+
^
922+
HINT: No function matches the given name and argument types. You may need to add explicit type casts.
917923
SELECT cube_dim(ll_to_earth(60,90)) <= 3;
918924
?column?
919925
----------
@@ -929,7 +935,9 @@ SELECT abs(cube_distance(ll_to_earth(60,90), '(0)'::cube) / earth() - 1) <
929935

930936
SELECT is_point(ll_to_earth(-30,-90));
931937
ERROR: function is_point(earth) does not exist
932-
HINT: No function matches the given name and argument types. You may need to add explicit typecasts.
938+
LINE 1: SELECT is_point(ll_to_earth(-30,-90));
939+
^
940+
HINT: No function matches the given name and argument types. You may need to add explicit type casts.
933941
SELECT cube_dim(ll_to_earth(-30,-90)) <= 3;
934942
?column?
935943
----------

‎src/backend/access/common/tupdesc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/common/tupdesc.c,v 1.114 2006/03/05 15:58:20 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/common/tupdesc.c,v 1.115 2006/03/14 22:48:18 tgl Exp $
1212
*
1313
* NOTES
1414
* some of the executor utility code such as "ExecTypeFromTL" should be
@@ -499,7 +499,7 @@ BuildDescForRelation(List *schema)
499499
attname)));
500500

501501
TupleDescInitEntry(desc,attnum,attname,
502-
typenameTypeId(entry->typename),
502+
typenameTypeId(NULL,entry->typename),
503503
atttypmod,attdim);
504504

505505
/* Fill in additional stuff not handled by TupleDescInitEntry */

‎src/backend/catalog/pg_aggregate.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/pg_aggregate.c,v 1.78 2006/03/05 15:58:23 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/pg_aggregate.c,v 1.79 2006/03/14 22:48:18 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -171,9 +171,9 @@ AggregateCreate(const char *aggName,
171171

172172
/* handle sortop, if supplied */
173173
if (aggsortopName)
174-
sortop=LookupOperName(aggsortopName,
174+
sortop=LookupOperName(NULL,aggsortopName,
175175
aggBaseType,aggBaseType,
176-
false);
176+
false,-1);
177177

178178
/*
179179
* Everything looks okay. Try to create the pg_proc entry for the

‎src/backend/catalog/pg_operator.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/pg_operator.c,v 1.95 2006/03/05 15:58:23 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/pg_operator.c,v 1.96 2006/03/14 22:48:18 tgl Exp $
1212
*
1313
* NOTES
1414
* these routines moved here from commands/define.c and somewhat cleaned up.
@@ -175,8 +175,9 @@ OperatorLookup(List *operatorName,
175175
OidoperatorObjectId;
176176
RegProcedureoprcode;
177177

178-
operatorObjectId=LookupOperName(operatorName,leftObjectId,
179-
rightObjectId, true);
178+
operatorObjectId=LookupOperName(NULL,operatorName,
179+
leftObjectId,rightObjectId,
180+
true,-1);
180181
if (!OidIsValid(operatorObjectId))
181182
{
182183
*defined= false;

‎src/backend/commands/aggregatecmds.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/commands/aggregatecmds.c,v 1.32 2006/03/05 15:58:23 momjian Exp $
12+
* $PostgreSQL: pgsql/src/backend/commands/aggregatecmds.c,v 1.33 2006/03/14 22:48:18 tgl Exp $
1313
*
1414
* DESCRIPTION
1515
* The "DefineFoo" routines take the parse tree and pick out the
@@ -129,9 +129,9 @@ DefineAggregate(List *names, List *parameters)
129129
if (pg_strcasecmp(TypeNameToString(baseType),"ANY")==0)
130130
baseTypeId=ANYOID;
131131
else
132-
baseTypeId=typenameTypeId(baseType);
132+
baseTypeId=typenameTypeId(NULL,baseType);
133133

134-
transTypeId=typenameTypeId(transType);
134+
transTypeId=typenameTypeId(NULL,transType);
135135
if (get_typtype(transTypeId)=='p'&&
136136
transTypeId!=ANYARRAYOID&&
137137
transTypeId!=ANYELEMENTOID)
@@ -176,7 +176,7 @@ RemoveAggregate(RemoveAggrStmt *stmt)
176176
* that the aggregate is to apply to all basetypes (eg, COUNT).
177177
*/
178178
if (aggType)
179-
basetypeID=typenameTypeId(aggType);
179+
basetypeID=typenameTypeId(NULL,aggType);
180180
else
181181
basetypeID=ANYOID;
182182

@@ -231,7 +231,7 @@ RenameAggregate(List *name, TypeName *basetype, const char *newname)
231231
* COUNT).
232232
*/
233233
if (basetype)
234-
basetypeOid=typenameTypeId(basetype);
234+
basetypeOid=typenameTypeId(NULL,basetype);
235235
else
236236
basetypeOid=ANYOID;
237237

@@ -311,7 +311,7 @@ AlterAggregateOwner(List *name, TypeName *basetype, Oid newOwnerId)
311311
* COUNT).
312312
*/
313313
if (basetype)
314-
basetypeOid=typenameTypeId(basetype);
314+
basetypeOid=typenameTypeId(NULL,basetype);
315315
else
316316
basetypeOid=ANYOID;
317317

‎src/backend/commands/comment.c

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Copyright (c) 1996-2006, PostgreSQL Global Development Group
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/commands/comment.c,v 1.87 2006/03/05 15:58:23 momjian Exp $
10+
* $PostgreSQL: pgsql/src/backend/commands/comment.c,v 1.88 2006/03/14 22:48:18 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -39,6 +39,7 @@
3939
#include"commands/dbcommands.h"
4040
#include"commands/tablespace.h"
4141
#include"miscadmin.h"
42+
#include"nodes/makefuncs.h"
4243
#include"parser/parse_func.h"
4344
#include"parser/parse_oper.h"
4445
#include"parser/parse_type.h"
@@ -846,13 +847,11 @@ CommentType(List *typename, char *comment)
846847
Oidoid;
847848

848849
/* XXX a bit of a crock; should accept TypeName in COMMENT syntax */
849-
tname=makeNode(TypeName);
850-
tname->names=typename;
851-
tname->typmod=-1;
850+
tname=makeTypeNameFromNameList(typename);
852851

853852
/* Find the type's oid */
854853

855-
oid=typenameTypeId(tname);
854+
oid=typenameTypeId(NULL,tname);
856855

857856
/* Check object security */
858857

@@ -881,7 +880,7 @@ CommentAggregate(List *aggregate, List *arguments, char *comment)
881880

882881
/* First, attempt to determine the base aggregate oid */
883882
if (aggtype)
884-
baseoid=typenameTypeId(aggtype);
883+
baseoid=typenameTypeId(NULL,aggtype);
885884
else
886885
baseoid=ANYOID;
887886

@@ -945,9 +944,11 @@ CommentOperator(List *opername, List *arguments, char *comment)
945944
Oidoid;
946945

947946
/* Look up the operator */
948-
oid=LookupOperNameTypeNames(opername,typenode1,typenode2, false);
947+
oid=LookupOperNameTypeNames(NULL,opername,
948+
typenode1,typenode2,
949+
false,-1);
949950

950-
/*Valid user'sability to comment on this operator */
951+
/*Check user'sprivilege to comment on this operator */
951952
if (!pg_oper_ownercheck(oid,GetUserId()))
952953
aclcheck_error(ACLCHECK_NOT_OWNER,ACL_KIND_OPER,
953954
NameListToString(opername));
@@ -1352,19 +1353,8 @@ CommentCast(List *qualname, List *arguments, char *comment)
13521353
targettype= (TypeName*)linitial(arguments);
13531354
Assert(IsA(targettype,TypeName));
13541355

1355-
sourcetypeid=typenameTypeId(sourcetype);
1356-
if (!OidIsValid(sourcetypeid))
1357-
ereport(ERROR,
1358-
(errcode(ERRCODE_UNDEFINED_OBJECT),
1359-
errmsg("source data type %s does not exist",
1360-
TypeNameToString(sourcetype))));
1361-
1362-
targettypeid=typenameTypeId(targettype);
1363-
if (!OidIsValid(targettypeid))
1364-
ereport(ERROR,
1365-
(errcode(ERRCODE_UNDEFINED_OBJECT),
1366-
errmsg("target data type %s does not exist",
1367-
TypeNameToString(targettype))));
1356+
sourcetypeid=typenameTypeId(NULL,sourcetype);
1357+
targettypeid=typenameTypeId(NULL,targettype);
13681358

13691359
tuple=SearchSysCache(CASTSOURCETARGET,
13701360
ObjectIdGetDatum(sourcetypeid),

‎src/backend/commands/define.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/commands/define.c,v 1.94 2006/03/05 15:58:24 momjian Exp $
12+
* $PostgreSQL: pgsql/src/backend/commands/define.c,v 1.95 2006/03/14 22:48:18 tgl Exp $
1313
*
1414
* DESCRIPTION
1515
* The "DefineFoo" routines take the parse tree and pick out the
@@ -37,6 +37,7 @@
3737

3838
#include"catalog/namespace.h"
3939
#include"commands/defrem.h"
40+
#include"nodes/makefuncs.h"
4041
#include"parser/parse_type.h"
4142
#include"parser/scansup.h"
4243
#include"utils/int8.h"
@@ -219,14 +220,8 @@ defGetTypeName(DefElem *def)
219220
caseT_TypeName:
220221
return (TypeName*)def->arg;
221222
caseT_String:
222-
{
223-
/* Allow quoted typename for backwards compatibility */
224-
TypeName*n=makeNode(TypeName);
225-
226-
n->names=list_make1(def->arg);
227-
n->typmod=-1;
228-
returnn;
229-
}
223+
/* Allow quoted typename for backwards compatibility */
224+
returnmakeTypeNameFromNameList(list_make1(def->arg));
230225
default:
231226
ereport(ERROR,
232227
(errcode(ERRCODE_SYNTAX_ERROR),

‎src/backend/commands/functioncmds.c

Lines changed: 8 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/commands/functioncmds.c,v 1.72 2006/03/05 15:58:24 momjian Exp $
13+
* $PostgreSQL: pgsql/src/backend/commands/functioncmds.c,v 1.73 2006/03/14 22:48:18 tgl Exp $
1414
*
1515
* DESCRIPTION
1616
* These routines take the parse tree and pick out the
@@ -75,7 +75,7 @@ compute_return_type(TypeName *returnType, Oid languageOid,
7575
{
7676
Oidrettype;
7777

78-
rettype=LookupTypeName(returnType);
78+
rettype=LookupTypeName(NULL,returnType);
7979

8080
if (OidIsValid(rettype))
8181
{
@@ -174,7 +174,7 @@ examine_parameter_list(List *parameters, Oid languageOid,
174174
TypeName*t=fp->argType;
175175
Oidtoid;
176176

177-
toid=LookupTypeName(t);
177+
toid=LookupTypeName(NULL,t);
178178
if (OidIsValid(toid))
179179
{
180180
if (!get_typisdefined(toid))
@@ -1152,33 +1152,10 @@ CreateCast(CreateCastStmt *stmt)
11521152
ObjectAddressmyself,
11531153
referenced;
11541154

1155-
sourcetypeid=LookupTypeName(stmt->sourcetype);
1156-
if (!OidIsValid(sourcetypeid))
1157-
ereport(ERROR,
1158-
(errcode(ERRCODE_UNDEFINED_OBJECT),
1159-
errmsg("source data type %s does not exist",
1160-
TypeNameToString(stmt->sourcetype))));
1161-
1162-
targettypeid=LookupTypeName(stmt->targettype);
1163-
if (!OidIsValid(targettypeid))
1164-
ereport(ERROR,
1165-
(errcode(ERRCODE_UNDEFINED_OBJECT),
1166-
errmsg("target data type %s does not exist",
1167-
TypeNameToString(stmt->targettype))));
1168-
1169-
/* No shells, no pseudo-types allowed */
1170-
if (!get_typisdefined(sourcetypeid))
1171-
ereport(ERROR,
1172-
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
1173-
errmsg("source data type %s is only a shell",
1174-
TypeNameToString(stmt->sourcetype))));
1175-
1176-
if (!get_typisdefined(targettypeid))
1177-
ereport(ERROR,
1178-
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
1179-
errmsg("target data type %s is only a shell",
1180-
TypeNameToString(stmt->targettype))));
1155+
sourcetypeid=typenameTypeId(NULL,stmt->sourcetype);
1156+
targettypeid=typenameTypeId(NULL,stmt->targettype);
11811157

1158+
/* No pseudo-types allowed */
11821159
if (get_typtype(sourcetypeid)=='p')
11831160
ereport(ERROR,
11841161
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
@@ -1400,19 +1377,8 @@ DropCast(DropCastStmt *stmt)
14001377
HeapTupletuple;
14011378
ObjectAddressobject;
14021379

1403-
sourcetypeid=LookupTypeName(stmt->sourcetype);
1404-
if (!OidIsValid(sourcetypeid))
1405-
ereport(ERROR,
1406-
(errcode(ERRCODE_UNDEFINED_OBJECT),
1407-
errmsg("source data type %s does not exist",
1408-
TypeNameToString(stmt->sourcetype))));
1409-
1410-
targettypeid=LookupTypeName(stmt->targettype);
1411-
if (!OidIsValid(targettypeid))
1412-
ereport(ERROR,
1413-
(errcode(ERRCODE_UNDEFINED_OBJECT),
1414-
errmsg("target data type %s does not exist",
1415-
TypeNameToString(stmt->targettype))));
1380+
sourcetypeid=typenameTypeId(NULL,stmt->sourcetype);
1381+
targettypeid=typenameTypeId(NULL,stmt->targettype);
14161382

14171383
tuple=SearchSysCache(CASTSOURCETARGET,
14181384
ObjectIdGetDatum(sourcetypeid),

‎src/backend/commands/opclasscmds.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/commands/opclasscmds.c,v 1.42 2006/03/05 15:58:24 momjian Exp $
12+
* $PostgreSQL: pgsql/src/backend/commands/opclasscmds.c,v 1.43 2006/03/14 22:48:18 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -144,7 +144,7 @@ DefineOpClass(CreateOpClassStmt *stmt)
144144
errmsg("must be superuser to create an operator class")));
145145

146146
/* Look up the datatype */
147-
typeoid=typenameTypeId(stmt->datatype);
147+
typeoid=typenameTypeId(NULL,stmt->datatype);
148148

149149
#ifdefNOT_USED
150150
/* XXX this is unnecessary given the superuser check above */
@@ -185,16 +185,16 @@ DefineOpClass(CreateOpClassStmt *stmt)
185185
TypeName*typeName1= (TypeName*)linitial(item->args);
186186
TypeName*typeName2= (TypeName*)lsecond(item->args);
187187

188-
operOid=LookupOperNameTypeNames(item->name,
189-
typeName1,
190-
typeName2,
191-
false);
188+
operOid=LookupOperNameTypeNames(NULL,item->name,
189+
typeName1,typeName2,
190+
false,-1);
192191
}
193192
else
194193
{
195194
/* Default to binary op on input datatype */
196-
operOid=LookupOperName(item->name,typeoid,typeoid,
197-
false);
195+
operOid=LookupOperName(NULL,item->name,
196+
typeoid,typeoid,
197+
false,-1);
198198
}
199199

200200
#ifdefNOT_USED
@@ -246,7 +246,7 @@ DefineOpClass(CreateOpClassStmt *stmt)
246246
ereport(ERROR,
247247
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
248248
errmsg("storage type specified more than once")));
249-
storageoid=typenameTypeId(item->storedtype);
249+
storageoid=typenameTypeId(NULL,item->storedtype);
250250

251251
#ifdefNOT_USED
252252
/* XXX this is unnecessary given the superuser check above */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp