mirror of
https://github.com/postgres/postgres.git
synced 2025-10-27 00:12:01 +03:00
Improve reporting of "conflicting or redundant options" errors.
When reporting "conflicting or redundant options" errors, try to ensure that errposition() is used, to help the user identify the offending option. Formerly, errposition() was invoked in less than 60% of cases. This patch raises that to over 90%, but there remain a few places where the ParseState is not readily available. Using errdetail() might improve the error in such cases, but that is left as a task for the future. Additionally, since this error is thrown from over 100 places in the codebase, introduce a dedicated function to throw it, reducing code duplication. Extracted from a slightly larger patch by Vignesh C. Reviewed by Bharath Rupireddy, Alvaro Herrera, Dilip Kumar, Hou Zhijie, Peter Smith, Daniel Gustafsson, Julien Rouhaud and me. Discussion: https://postgr.es/m/CALDaNm33FFSS5tVyvmkoK2cCMuDVxcui=gFrjti9ROfynqSAGA@mail.gmail.com
This commit is contained in:
@@ -55,7 +55,8 @@ static void PublicationAddTables(Oid pubid, List *rels, bool if_not_exists,
|
||||
static void PublicationDropTables(Oid pubid, List *rels, bool missing_ok);
|
||||
|
||||
static void
|
||||
parse_publication_options(List *options,
|
||||
parse_publication_options(ParseState *pstate,
|
||||
List *options,
|
||||
bool *publish_given,
|
||||
PublicationActions *pubactions,
|
||||
bool *publish_via_partition_root_given,
|
||||
@@ -85,9 +86,7 @@ parse_publication_options(List *options,
|
||||
ListCell *lc;
|
||||
|
||||
if (*publish_given)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("conflicting or redundant options")));
|
||||
errorConflictingDefElem(defel, pstate);
|
||||
|
||||
/*
|
||||
* If publish option was given only the explicitly listed actions
|
||||
@@ -128,9 +127,7 @@ parse_publication_options(List *options,
|
||||
else if (strcmp(defel->defname, "publish_via_partition_root") == 0)
|
||||
{
|
||||
if (*publish_via_partition_root_given)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("conflicting or redundant options")));
|
||||
errorConflictingDefElem(defel, pstate);
|
||||
*publish_via_partition_root_given = true;
|
||||
*publish_via_partition_root = defGetBoolean(defel);
|
||||
}
|
||||
@@ -145,7 +142,7 @@ parse_publication_options(List *options,
|
||||
* Create new publication.
|
||||
*/
|
||||
ObjectAddress
|
||||
CreatePublication(CreatePublicationStmt *stmt)
|
||||
CreatePublication(ParseState *pstate, CreatePublicationStmt *stmt)
|
||||
{
|
||||
Relation rel;
|
||||
ObjectAddress myself;
|
||||
@@ -192,7 +189,8 @@ CreatePublication(CreatePublicationStmt *stmt)
|
||||
DirectFunctionCall1(namein, CStringGetDatum(stmt->pubname));
|
||||
values[Anum_pg_publication_pubowner - 1] = ObjectIdGetDatum(GetUserId());
|
||||
|
||||
parse_publication_options(stmt->options,
|
||||
parse_publication_options(pstate,
|
||||
stmt->options,
|
||||
&publish_given, &pubactions,
|
||||
&publish_via_partition_root_given,
|
||||
&publish_via_partition_root);
|
||||
@@ -256,8 +254,8 @@ CreatePublication(CreatePublicationStmt *stmt)
|
||||
* Change options of a publication.
|
||||
*/
|
||||
static void
|
||||
AlterPublicationOptions(AlterPublicationStmt *stmt, Relation rel,
|
||||
HeapTuple tup)
|
||||
AlterPublicationOptions(ParseState *pstate, AlterPublicationStmt *stmt,
|
||||
Relation rel, HeapTuple tup)
|
||||
{
|
||||
bool nulls[Natts_pg_publication];
|
||||
bool replaces[Natts_pg_publication];
|
||||
@@ -269,7 +267,8 @@ AlterPublicationOptions(AlterPublicationStmt *stmt, Relation rel,
|
||||
ObjectAddress obj;
|
||||
Form_pg_publication pubform;
|
||||
|
||||
parse_publication_options(stmt->options,
|
||||
parse_publication_options(pstate,
|
||||
stmt->options,
|
||||
&publish_given, &pubactions,
|
||||
&publish_via_partition_root_given,
|
||||
&publish_via_partition_root);
|
||||
@@ -434,7 +433,7 @@ AlterPublicationTables(AlterPublicationStmt *stmt, Relation rel,
|
||||
* AlterPublicationTables.
|
||||
*/
|
||||
void
|
||||
AlterPublication(AlterPublicationStmt *stmt)
|
||||
AlterPublication(ParseState *pstate, AlterPublicationStmt *stmt)
|
||||
{
|
||||
Relation rel;
|
||||
HeapTuple tup;
|
||||
@@ -459,7 +458,7 @@ AlterPublication(AlterPublicationStmt *stmt)
|
||||
stmt->pubname);
|
||||
|
||||
if (stmt->options)
|
||||
AlterPublicationOptions(stmt, rel, tup);
|
||||
AlterPublicationOptions(pstate, stmt, rel, tup);
|
||||
else
|
||||
AlterPublicationTables(stmt, rel, tup);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user