diff --git a/src/backend/commands/publicationcmds.c b/src/backend/commands/publicationcmds.c index 0f9790c4c0f..24a4d81588c 100644 --- a/src/backend/commands/publicationcmds.c +++ b/src/backend/commands/publicationcmds.c @@ -2095,15 +2095,8 @@ AlterPublicationSchemaExceptTables(AlterPublicationStmt *stmt, if (schemaidlist == NIL && !is_schema_publication(pubid)) return; - /* - * Dropping a schema from a publication removes all its EXCEPT entries via - * cascade. The concept of "drop all schema tables from the publication - * EXCEPT these ones" is not supported. - */ - if (stmt->action == AP_DropObjects) - ereport(ERROR, - (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("EXCEPT clause is not supported with DROP in ALTER PUBLICATION"))); + /* DROP takes no EXCEPT clause; preprocess_pubobj_list() rejects that */ + Assert(stmt->action != AP_DropObjects); if (stmt->action == AP_AddObjects) { diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 14520a5ccab..f20efde5f85 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -207,7 +207,7 @@ static void preprocess_pub_all_objtype_list(List *all_objects_list, bool *all_tables, bool *all_sequences, core_yyscan_t yyscanner); -static void preprocess_pubobj_list(List *pubobjspec_list, +static void preprocess_pubobj_list(List *pubobjspec_list, bool allow_except, core_yyscan_t yyscanner); static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query); @@ -11315,7 +11315,7 @@ CreatePublicationStmt: n->pubname = $3; n->options = $6; n->pubobjects = (List *) $5; - preprocess_pubobj_list(n->pubobjects, yyscanner); + preprocess_pubobj_list(n->pubobjects, true, yyscanner); $$ = (Node *) n; } ; @@ -11506,7 +11506,7 @@ AlterPublicationStmt: n->pubname = $3; n->pubobjects = $5; - preprocess_pubobj_list(n->pubobjects, yyscanner); + preprocess_pubobj_list(n->pubobjects, true, yyscanner); n->action = AP_AddObjects; n->for_all_tables = false; $$ = (Node *) n; @@ -11517,7 +11517,7 @@ AlterPublicationStmt: n->pubname = $3; n->pubobjects = $5; - preprocess_pubobj_list(n->pubobjects, yyscanner); + preprocess_pubobj_list(n->pubobjects, true, yyscanner); n->action = AP_SetObjects; n->for_all_tables = false; $$ = (Node *) n; @@ -11540,7 +11540,7 @@ AlterPublicationStmt: n->pubname = $3; n->pubobjects = $5; - preprocess_pubobj_list(n->pubobjects, yyscanner); + preprocess_pubobj_list(n->pubobjects, false, yyscanner); n->action = AP_DropObjects; n->for_all_tables = false; $$ = (Node *) n; @@ -20879,7 +20879,8 @@ preprocess_pub_all_objtype_list(List *all_objects_list, List **pubobjects, * output list once the schema OID is known. */ static void -preprocess_pubobj_list(List *pubobjspec_list, core_yyscan_t yyscanner) +preprocess_pubobj_list(List *pubobjspec_list, bool allow_except, + core_yyscan_t yyscanner) { ListCell *cell; PublicationObjSpec *pubobj; @@ -20903,6 +20904,18 @@ preprocess_pubobj_list(List *pubobjspec_list, core_yyscan_t yyscanner) if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION) pubobj->pubobjtype = prevobjtype; + /* + * Dropping a schema from a publication removes all of its EXCEPT + * entries along with it. The concept of "drop all schema tables from + * the publication EXCEPT these ones" is not supported, so DROP takes + * no EXCEPT clause. + */ + if (!allow_except && pubobj->except_tables != NIL) + ereport(ERROR, + errcode(ERRCODE_SYNTAX_ERROR), + errmsg("EXCEPT clause is not supported with DROP in ALTER PUBLICATION"), + parser_errposition(pubobj->location)); + if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLE) { /* EXCEPT is not valid for table objects */