aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/sequence.c
diff options
context:
space:
mode:
authorPeter Eisentraut <peter_e@gmx.net>2016-09-06 12:00:00 -0400
committerPeter Eisentraut <peter_e@gmx.net>2016-09-06 12:00:00 -0400
commit49eb0fd0972d14014dd3533b1f1bf8c94c899883 (patch)
treebcbfa5cf8f49c1b73066a5c4eaf80f33fc4ecc53 /src/backend/commands/sequence.c
parent975768f8eae2581b89ceafe8b16a77ff375207fe (diff)
downloadpostgresql-49eb0fd0972d14014dd3533b1f1bf8c94c899883.tar.gz
postgresql-49eb0fd0972d14014dd3533b1f1bf8c94c899883.zip
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>
Diffstat (limited to 'src/backend/commands/sequence.c')
-rw-r--r--src/backend/commands/sequence.c36
1 files changed, 22 insertions, 14 deletions
diff --git a/src/backend/commands/sequence.c b/src/backend/commands/sequence.c
index c98f9811119..fc3a8eebce3 100644
--- a/src/backend/commands/sequence.c
+++ b/src/backend/commands/sequence.c
@@ -94,7 +94,7 @@ static void create_seq_hashtable(void);
static void init_sequence(Oid relid, SeqTable *p_elm, Relation *p_rel);
static Form_pg_sequence read_seq_tuple(SeqTable elm, Relation rel,
Buffer *buf, HeapTuple seqtuple);
-static void init_params(List *options, bool isInit,
+static void init_params(ParseState *pstate, List *options, bool isInit,
Form_pg_sequence new, List **owned_by);
static void do_setval(Oid relid, int64 next, bool iscalled);
static void process_owned_by(Relation seqrel, List *owned_by);
@@ -105,7 +105,7 @@ static void process_owned_by(Relation seqrel, List *owned_by);
* Creates a new sequence relation
*/
ObjectAddress
-DefineSequence(CreateSeqStmt *seq)
+DefineSequence(ParseState *pstate, CreateSeqStmt *seq)
{
FormData_pg_sequence new;
List *owned_by;
@@ -145,7 +145,7 @@ DefineSequence(CreateSeqStmt *seq)
}
/* Check and set all option values */
- init_params(seq->options, true, &new, &owned_by);
+ init_params(pstate, seq->options, true, &new, &owned_by);
/*
* Create relation (and fill value[] and null[] for the tuple)
@@ -404,7 +404,7 @@ fill_seq_with_data(Relation rel, HeapTuple tuple)
* Modify the definition of a sequence relation
*/
ObjectAddress
-AlterSequence(AlterSeqStmt *stmt)
+AlterSequence(ParseState *pstate, AlterSeqStmt *stmt)
{
Oid relid;
SeqTable elm;
@@ -440,7 +440,7 @@ AlterSequence(AlterSeqStmt *stmt)
memcpy(&new, seq, sizeof(FormData_pg_sequence));
/* Check and set new values */
- init_params(stmt->options, false, &new, &owned_by);
+ init_params(pstate, stmt->options, false, &new, &owned_by);
/* Clear local cache so that we don't think we have cached numbers */
/* Note that we do not change the currval() state */
@@ -1163,7 +1163,7 @@ read_seq_tuple(SeqTable elm, Relation rel, Buffer *buf, HeapTuple seqtuple)
* otherwise, do not change existing options that aren't explicitly overridden.
*/
static void
-init_params(List *options, bool isInit,
+init_params(ParseState *pstate, List *options, bool isInit,
Form_pg_sequence new, List **owned_by)
{
DefElem *start_value = NULL;
@@ -1186,7 +1186,8 @@ init_params(List *options, bool isInit,
if (increment_by)
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("conflicting or redundant options")));
+ errmsg("conflicting or redundant options"),
+ parser_errposition(pstate, defel->location)));
increment_by = defel;
}
else if (strcmp(defel->defname, "start") == 0)
@@ -1194,7 +1195,8 @@ init_params(List *options, bool isInit,
if (start_value)
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("conflicting or redundant options")));
+ errmsg("conflicting or redundant options"),
+ parser_errposition(pstate, defel->location)));
start_value = defel;
}
else if (strcmp(defel->defname, "restart") == 0)
@@ -1202,7 +1204,8 @@ init_params(List *options, bool isInit,
if (restart_value)
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("conflicting or redundant options")));
+ errmsg("conflicting or redundant options"),
+ parser_errposition(pstate, defel->location)));
restart_value = defel;
}
else if (strcmp(defel->defname, "maxvalue") == 0)
@@ -1210,7 +1213,8 @@ init_params(List *options, bool isInit,
if (max_value)
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("conflicting or redundant options")));
+ errmsg("conflicting or redundant options"),
+ parser_errposition(pstate, defel->location)));
max_value = defel;
}
else if (strcmp(defel->defname, "minvalue") == 0)
@@ -1218,7 +1222,8 @@ init_params(List *options, bool isInit,
if (min_value)
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("conflicting or redundant options")));
+ errmsg("conflicting or redundant options"),
+ parser_errposition(pstate, defel->location)));
min_value = defel;
}
else if (strcmp(defel->defname, "cache") == 0)
@@ -1226,7 +1231,8 @@ init_params(List *options, bool isInit,
if (cache_value)
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("conflicting or redundant options")));
+ errmsg("conflicting or redundant options"),
+ parser_errposition(pstate, defel->location)));
cache_value = defel;
}
else if (strcmp(defel->defname, "cycle") == 0)
@@ -1234,7 +1240,8 @@ init_params(List *options, bool isInit,
if (is_cycled)
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("conflicting or redundant options")));
+ errmsg("conflicting or redundant options"),
+ parser_errposition(pstate, defel->location)));
is_cycled = defel;
}
else if (strcmp(defel->defname, "owned_by") == 0)
@@ -1242,7 +1249,8 @@ init_params(List *options, bool isInit,
if (*owned_by)
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("conflicting or redundant options")));
+ errmsg("conflicting or redundant options"),
+ parser_errposition(pstate, defel->location)));
*owned_by = defGetQualifiedName(defel);
}
else