Skip to content

Commit 49eb0fd

Browse files
committed
Add location field to DefElem
Add a location field to the DefElem struct, used to parse many utility commands. Update various error messages to supply error position information. To propogate the error position information in a more systematic way, create a ParseState in standard_ProcessUtility() and pass that to interested functions implementing the utility commands. This seems better than passing the query string and then reassembling a parse state ad hoc, which violates the encapsulation of the ParseState type. Reviewed-by: Pavel Stehule <pavel.stehule@gmail.com>
1 parent 975768f commit 49eb0fd

38 files changed

+438
-347
lines changed

contrib/file_fdw/file_fdw.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ file_fdw_validator(PG_FUNCTION_ARGS)
293293
/*
294294
* Now apply the core COPY code's validation logic for more checks.
295295
*/
296-
ProcessCopyOptions(NULL, true, other_options);
296+
ProcessCopyOptions(NULL, NULL, true, other_options);
297297

298298
/*
299299
* Filename option is required for file_fdw foreign tables.
@@ -455,10 +455,10 @@ get_file_fdw_attribute_options(Oid relid)
455455
* force_null options set
456456
*/
457457
if (fnncolumns != NIL)
458-
options = lappend(options, makeDefElem("force_not_null", (Node *) fnncolumns));
458+
options = lappend(options, makeDefElem("force_not_null", (Node *) fnncolumns, -1));
459459

460460
if (fncolumns != NIL)
461-
options = lappend(options, makeDefElem("force_null", (Node *) fncolumns));
461+
options = lappend(options, makeDefElem("force_null", (Node *) fncolumns, -1));
462462

463463
return options;
464464
}
@@ -511,7 +511,7 @@ fileGetForeignPaths(PlannerInfo *root,
511511
foreigntableid,
512512
&columns))
513513
coptions = list_make1(makeDefElem("convert_selectively",
514-
(Node *) columns));
514+
(Node *) columns, -1));
515515

516516
/* Estimate costs */
517517
estimate_costs(root, baserel, fdw_private,
@@ -632,7 +632,8 @@ fileBeginForeignScan(ForeignScanState *node, int eflags)
632632
* Create CopyState from FDW options. We always acquire all columns, so
633633
* as to match the expected ScanTupleSlot signature.
634634
*/
635-
cstate = BeginCopyFrom(node->ss.ss_currentRelation,
635+
cstate = BeginCopyFrom(NULL,
636+
node->ss.ss_currentRelation,
636637
filename,
637638
false,
638639
NIL,
@@ -705,7 +706,8 @@ fileReScanForeignScan(ForeignScanState *node)
705706

706707
EndCopyFrom(festate->cstate);
707708

708-
festate->cstate = BeginCopyFrom(node->ss.ss_currentRelation,
709+
festate->cstate = BeginCopyFrom(NULL,
710+
node->ss.ss_currentRelation,
709711
festate->filename,
710712
false,
711713
NIL,
@@ -1053,7 +1055,7 @@ file_acquire_sample_rows(Relation onerel, int elevel,
10531055
/*
10541056
* Create CopyState from FDW options.
10551057
*/
1056-
cstate = BeginCopyFrom(onerel, filename, false, NIL, options);
1058+
cstate = BeginCopyFrom(NULL, onerel, filename, false, NIL, options);
10571059

10581060
/*
10591061
* Use per-tuple memory context to prevent leak of memory used to read

src/backend/access/common/reloptions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ untransformRelOptions(Datum options)
888888
*p++ = '\0';
889889
val = (Node *) makeString(pstrdup(p));
890890
}
891-
result = lappend(result, makeDefElem(pstrdup(s), val));
891+
result = lappend(result, makeDefElem(pstrdup(s), val, -1));
892892
}
893893

894894
return result;

src/backend/catalog/aclchk.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ getRelationsInNamespace(Oid namespaceId, char relkind)
849849
* ALTER DEFAULT PRIVILEGES statement
850850
*/
851851
void
852-
ExecAlterDefaultPrivilegesStmt(AlterDefaultPrivilegesStmt *stmt)
852+
ExecAlterDefaultPrivilegesStmt(ParseState *pstate, AlterDefaultPrivilegesStmt *stmt)
853853
{
854854
GrantStmt *action = stmt->action;
855855
InternalDefaultACL iacls;
@@ -871,15 +871,17 @@ ExecAlterDefaultPrivilegesStmt(AlterDefaultPrivilegesStmt *stmt)
871871
if (dnspnames)
872872
ereport(ERROR,
873873
(errcode(ERRCODE_SYNTAX_ERROR),
874-
errmsg("conflicting or redundant options")));
874+
errmsg("conflicting or redundant options"),
875+
parser_errposition(pstate, defel->location)));
875876
dnspnames = defel;
876877
}
877878
else if (strcmp(defel->defname, "roles") == 0)
878879
{
879880
if (drolespecs)
880881
ereport(ERROR,
881882
(errcode(ERRCODE_SYNTAX_ERROR),
882-
errmsg("conflicting or redundant options")));
883+
errmsg("conflicting or redundant options"),
884+
parser_errposition(pstate, defel->location)));
883885
drolespecs = defel;
884886
}
885887
else

src/backend/commands/aggregatecmds.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@
5252
* "parameters" is a list of DefElem representing the agg's definition clauses.
5353
*/
5454
ObjectAddress
55-
DefineAggregate(List *name, List *args, bool oldstyle, List *parameters,
56-
const char *queryString)
55+
DefineAggregate(ParseState *pstate, List *name, List *args, bool oldstyle, List *parameters)
5756
{
5857
char *aggName;
5958
Oid aggNamespace;
@@ -287,10 +286,10 @@ DefineAggregate(List *name, List *args, bool oldstyle, List *parameters,
287286
errmsg("basetype is redundant with aggregate input type specification")));
288287

289288
numArgs = list_length(args);
290-
interpret_function_parameter_list(args,
289+
interpret_function_parameter_list(pstate,
290+
args,
291291
InvalidOid,
292292
true, /* is an aggregate */
293-
queryString,
294293
&parameterTypes,
295294
&allParameterTypes,
296295
&parameterModes,

src/backend/commands/collationcmds.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
* CREATE COLLATION
3939
*/
4040
ObjectAddress
41-
DefineCollation(List *names, List *parameters)
41+
DefineCollation(ParseState *pstate, List *names, List *parameters)
4242
{
4343
char *collName;
4444
Oid collNamespace;
@@ -78,7 +78,8 @@ DefineCollation(List *names, List *parameters)
7878
ereport(ERROR,
7979
(errcode(ERRCODE_SYNTAX_ERROR),
8080
errmsg("collation attribute \"%s\" not recognized",
81-
defel->defname)));
81+
defel->defname),
82+
parser_errposition(pstate, defel->location)));
8283
break;
8384
}
8485

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy