Add location field to DefElem
authorPeter Eisentraut <peter_e@gmx.net>
Tue, 6 Sep 2016 16:00:00 +0000 (12:00 -0400)
committerPeter Eisentraut <peter_e@gmx.net>
Tue, 6 Sep 2016 16:00:00 +0000 (12:00 -0400)
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>
38 files changed:
contrib/file_fdw/file_fdw.c
src/backend/access/common/reloptions.c
src/backend/catalog/aclchk.c
src/backend/commands/aggregatecmds.c
src/backend/commands/collationcmds.c
src/backend/commands/copy.c
src/backend/commands/dbcommands.c
src/backend/commands/define.c
src/backend/commands/explain.c
src/backend/commands/extension.c
src/backend/commands/functioncmds.c
src/backend/commands/sequence.c
src/backend/commands/tsearchcmds.c
src/backend/commands/typecmds.c
src/backend/commands/user.c
src/backend/commands/view.c
src/backend/nodes/copyfuncs.c
src/backend/nodes/equalfuncs.c
src/backend/nodes/makefuncs.c
src/backend/nodes/outfuncs.c
src/backend/nodes/readfuncs.c
src/backend/parser/gram.y
src/backend/parser/parse_utilcmd.c
src/backend/replication/logical/logicalfuncs.c
src/backend/replication/repl_gram.y
src/backend/tcop/utility.c
src/include/commands/collationcmds.h
src/include/commands/copy.h
src/include/commands/dbcommands.h
src/include/commands/defrem.h
src/include/commands/explain.h
src/include/commands/extension.h
src/include/commands/sequence.h
src/include/commands/typecmds.h
src/include/commands/user.h
src/include/nodes/makefuncs.h
src/include/nodes/parsenodes.h
src/include/utils/acl.h

index b42de873e0f56ced19c15ed15a88431b7202ebb7..b4719913183e16f99d5998a8d2c5e9b994427480 100644 (file)
@@ -293,7 +293,7 @@ file_fdw_validator(PG_FUNCTION_ARGS)
        /*
         * Now apply the core COPY code's validation logic for more checks.
         */
-       ProcessCopyOptions(NULL, true, other_options);
+       ProcessCopyOptions(NULL, NULL, true, other_options);
 
        /*
         * Filename option is required for file_fdw foreign tables.
@@ -455,10 +455,10 @@ get_file_fdw_attribute_options(Oid relid)
         * force_null options set
         */
        if (fnncolumns != NIL)
-               options = lappend(options, makeDefElem("force_not_null", (Node *) fnncolumns));
+               options = lappend(options, makeDefElem("force_not_null", (Node *) fnncolumns, -1));
 
        if (fncolumns != NIL)
-               options = lappend(options, makeDefElem("force_null", (Node *) fncolumns));
+               options = lappend(options, makeDefElem("force_null", (Node *) fncolumns, -1));
 
        return options;
 }
@@ -511,7 +511,7 @@ fileGetForeignPaths(PlannerInfo *root,
                                                                                  foreigntableid,
                                                                                  &columns))
                coptions = list_make1(makeDefElem("convert_selectively",
-                                                                                 (Node *) columns));
+                                                                                 (Node *) columns, -1));
 
        /* Estimate costs */
        estimate_costs(root, baserel, fdw_private,
@@ -632,7 +632,8 @@ fileBeginForeignScan(ForeignScanState *node, int eflags)
         * Create CopyState from FDW options.  We always acquire all columns, so
         * as to match the expected ScanTupleSlot signature.
         */
-       cstate = BeginCopyFrom(node->ss.ss_currentRelation,
+       cstate = BeginCopyFrom(NULL,
+                                                  node->ss.ss_currentRelation,
                                                   filename,
                                                   false,
                                                   NIL,
@@ -705,7 +706,8 @@ fileReScanForeignScan(ForeignScanState *node)
 
        EndCopyFrom(festate->cstate);
 
-       festate->cstate = BeginCopyFrom(node->ss.ss_currentRelation,
+       festate->cstate = BeginCopyFrom(NULL,
+                                                                       node->ss.ss_currentRelation,
                                                                        festate->filename,
                                                                        false,
                                                                        NIL,
@@ -1053,7 +1055,7 @@ file_acquire_sample_rows(Relation onerel, int elevel,
        /*
         * Create CopyState from FDW options.
         */
-       cstate = BeginCopyFrom(onerel, filename, false, NIL, options);
+       cstate = BeginCopyFrom(NULL, onerel, filename, false, NIL, options);
 
        /*
         * Use per-tuple memory context to prevent leak of memory used to read
index ba1f3aafed7fc182fabb5ed127d980d1ec45bef5..83a97b06ab85bdfaa04c82bf2479948a2cc68849 100644 (file)
@@ -888,7 +888,7 @@ untransformRelOptions(Datum options)
                        *p++ = '\0';
                        val = (Node *) makeString(pstrdup(p));
                }
-               result = lappend(result, makeDefElem(pstrdup(s), val));
+               result = lappend(result, makeDefElem(pstrdup(s), val, -1));
        }
 
        return result;
index a585c3ad19a35f783cf9be9958914f20a74f003f..c0df6710d1d110efbf767c82e12f15c793dadff3 100644 (file)
@@ -849,7 +849,7 @@ getRelationsInNamespace(Oid namespaceId, char relkind)
  * ALTER DEFAULT PRIVILEGES statement
  */
 void
-ExecAlterDefaultPrivilegesStmt(AlterDefaultPrivilegesStmt *stmt)
+ExecAlterDefaultPrivilegesStmt(ParseState *pstate, AlterDefaultPrivilegesStmt *stmt)
 {
        GrantStmt  *action = stmt->action;
        InternalDefaultACL iacls;
@@ -871,7 +871,8 @@ ExecAlterDefaultPrivilegesStmt(AlterDefaultPrivilegesStmt *stmt)
                        if (dnspnames)
                                ereport(ERROR,
                                                (errcode(ERRCODE_SYNTAX_ERROR),
-                                                errmsg("conflicting or redundant options")));
+                                                errmsg("conflicting or redundant options"),
+                                                parser_errposition(pstate, defel->location)));
                        dnspnames = defel;
                }
                else if (strcmp(defel->defname, "roles") == 0)
@@ -879,7 +880,8 @@ ExecAlterDefaultPrivilegesStmt(AlterDefaultPrivilegesStmt *stmt)
                        if (drolespecs)
                                ereport(ERROR,
                                                (errcode(ERRCODE_SYNTAX_ERROR),
-                                                errmsg("conflicting or redundant options")));
+                                                errmsg("conflicting or redundant options"),
+                                                parser_errposition(pstate, defel->location)));
                        drolespecs = defel;
                }
                else
index d34c82c5baf7134d9f991dc64ff2bd838fc7eb92..b36f09eb7b924400d914c9d66682c309f151a582 100644 (file)
@@ -52,8 +52,7 @@
  * "parameters" is a list of DefElem representing the agg's definition clauses.
  */
 ObjectAddress
-DefineAggregate(List *name, List *args, bool oldstyle, List *parameters,
-                               const char *queryString)
+DefineAggregate(ParseState *pstate, List *name, List *args, bool oldstyle, List *parameters)
 {
        char       *aggName;
        Oid                     aggNamespace;
@@ -287,10 +286,10 @@ DefineAggregate(List *name, List *args, bool oldstyle, List *parameters,
                                         errmsg("basetype is redundant with aggregate input type specification")));