Rename some enums to use TABLE instead of REL.
authorAmit Kapila <akapila@postgresql.org>
Tue, 9 Nov 2021 03:09:33 +0000 (08:39 +0530)
committerAmit Kapila <akapila@postgresql.org>
Tue, 9 Nov 2021 03:09:33 +0000 (08:39 +0530)
Commit 5a2832465f introduced some enums to represent all tables in schema
publications and used REL in their names. Use TABLE instead of REL in
those enums to avoid confusion with other objects like SEQUENCES that can
be part of a publication in the future.

In the passing, (a) Change one of the newly introduced error messages to
make it consistent for Create and Alter commands, (b) add missing alias in
one of the SQL Statements that is used to print publications associated
with the table.

Reported-by: Tomas Vondra, Peter Smith
Author: Vignesh C
Reviewed-by: Hou Zhijie, Peter Smith
Discussion: https://www.postgresql.org/message-id/CALDaNm0OANxuJ6RXqwZsM1MSY4s19nuH3734j4a72etDwvBETQ%40mail.gmail.com

src/backend/commands/publicationcmds.c
src/backend/parser/gram.y
src/bin/pg_dump/pg_dump.c
src/bin/pg_dump/pg_dump.h
src/bin/pg_dump/pg_dump_sort.c
src/bin/psql/describe.c
src/include/nodes/parsenodes.h
src/test/regress/expected/publication.out

index d1fff13d2e9201040c4097551fde3f27bfa09141..7d4a0e95f6cb58998706b29a314510a4b06e3186 100644 (file)
@@ -169,13 +169,13 @@ ObjectsInPublicationToOids(List *pubobjspec_list, ParseState *pstate,
            case PUBLICATIONOBJ_TABLE:
                *rels = lappend(*rels, pubobj->pubtable);
                break;
-           case PUBLICATIONOBJ_REL_IN_SCHEMA:
+           case PUBLICATIONOBJ_TABLE_IN_SCHEMA:
                schemaid = get_namespace_oid(pubobj->name, false);
 
                /* Filter out duplicates if user specifies "sch1, sch1" */
                *schemas = list_append_unique_oid(*schemas, schemaid);
                break;
-           case PUBLICATIONOBJ_CURRSCHEMA:
+           case PUBLICATIONOBJ_TABLE_IN_CUR_SCHEMA:
                search_path = fetch_search_path(false);
                if (search_path == NIL) /* nothing valid in search_path? */
                    ereport(ERROR,
@@ -214,7 +214,7 @@ CheckObjSchemaNotAlreadyInPublication(List *rels, List *schemaidlist,
 
        if (list_member_oid(schemaidlist, relSchemaId))
        {
-           if (checkobjtype == PUBLICATIONOBJ_REL_IN_SCHEMA)
+           if (checkobjtype == PUBLICATIONOBJ_TABLE_IN_SCHEMA)
                ereport(ERROR,
                        errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                        errmsg("cannot add schema \"%s\" to publication",
@@ -613,7 +613,7 @@ AlterPublicationSchemas(AlterPublicationStmt *stmt,
        rels = OpenReliIdList(reloids);
 
        CheckObjSchemaNotAlreadyInPublication(rels, schemaidlist,
-                                             PUBLICATIONOBJ_REL_IN_SCHEMA);
+                                             PUBLICATIONOBJ_TABLE_IN_SCHEMA);
 
        CloseTableList(rels);
        PublicationAddSchemas(pubform->oid, schemaidlist, false, stmt);
index d0eb80e69cb975dae242f7c89836e89976fa1dc0..a6d0cefa6bb67505d78fcf10e485735d20859c92 100644 (file)
@@ -9662,14 +9662,14 @@ PublicationObjSpec:
            | ALL TABLES IN_P SCHEMA ColId
                {
                    $$ = makeNode(PublicationObjSpec);
-                   $$->pubobjtype = PUBLICATIONOBJ_REL_IN_SCHEMA;
+                   $$->pubobjtype = PUBLICATIONOBJ_TABLE_IN_SCHEMA;
                    $$->name = $5;
                    $$->location = @5;
                }
            | ALL TABLES IN_P SCHEMA CURRENT_SCHEMA
                {
                    $$ = makeNode(PublicationObjSpec);
-                   $$->pubobjtype = PUBLICATIONOBJ_CURRSCHEMA;
+                   $$->pubobjtype = PUBLICATIONOBJ_TABLE_IN_CUR_SCHEMA;
                    $$->location = @5;
                }
            | ColId
@@ -17323,7 +17323,7 @@ preprocess_pubobj_list(List *pubobjspec_list, core_yyscan_t yyscanner)
    if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
        ereport(ERROR,
                errcode(ERRCODE_SYNTAX_ERROR),
-               errmsg("FOR TABLE/FOR ALL TABLES IN SCHEMA should be specified before the table/schema name(s)"),
+               errmsg("TABLE/ALL TABLES IN SCHEMA should be specified before the table/schema name(s)"),
                parser_errposition(pubobj->location));
 
    foreach(cell, pubobjspec_list)
@@ -17351,17 +17351,17 @@ preprocess_pubobj_list(List *pubobjspec_list, core_yyscan_t yyscanner)
                pubobj->name = NULL;
            }
        }
-       else if (pubobj->pubobjtype == PUBLICATIONOBJ_REL_IN_SCHEMA ||
-                pubobj->pubobjtype == PUBLICATIONOBJ_CURRSCHEMA)
+       else if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLE_IN_SCHEMA ||
+                pubobj->pubobjtype == PUBLICATIONOBJ_TABLE_IN_CUR_SCHEMA)
        {
            /*
             * We can distinguish between the different type of schema
             * objects based on whether name and pubtable is set.
             */
            if (pubobj->name)
-               pubobj->pubobjtype = PUBLICATIONOBJ_REL_IN_SCHEMA;
+               pubobj->pubobjtype = PUBLICATIONOBJ_TABLE_IN_SCHEMA;
            else if (!pubobj->name && !pubobj->pubtable)
-               pubobj->pubobjtype = PUBLICATIONOBJ_CURRSCHEMA;
+               pubobj->pubobjtype = PUBLICATIONOBJ_TABLE_IN_CUR_SCHEMA;
            else
                ereport(ERROR,
                        errcode(ERRCODE_SYNTAX_ERROR),
index b9635a95b6f5d569f2120ecc660a1b68ec2d1167..7e98371d253b28276efcfc001a2300543a71f42a 100644 (file)
@@ -4194,7 +4194,7 @@ getPublicationNamespaces(Archive *fout)
            continue;
 
        /* OK, make a DumpableObject for this relationship */
-       pubsinfo[j].dobj.objType = DO_PUBLICATION_REL_IN_SCHEMA;
+       pubsinfo[j].dobj.objType = DO_PUBLICATION_TABLE_IN_SCHEMA;
        pubsinfo[j].dobj.catId.tableoid =
            atooid(PQgetvalue(res, i, i_tableoid));
        pubsinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
@@ -10331,7 +10331,7 @@ dumpDumpableObject(Archive *fout, const DumpableObject *dobj)
        case DO_PUBLICATION_REL:
            dumpPublicationTable(fout, (const PublicationRelInfo *) dobj);
            break;
-       case DO_PUBLICATION_REL_IN_SCHEMA:
+       case DO_PUBLICATION_TABLE_IN_SCHEMA:
            dumpPublicationNamespace(fout,
                                     (const PublicationSchemaInfo *) dobj);
            break;
@@ -18559,7 +18559,7 @@ addBoundaryDependencies(DumpableObject **dobjs, int numObjs,
            case DO_POLICY:
            case DO_PUBLICATION:
            case DO_PUBLICATION_REL:
-           case DO_PUBLICATION_REL_IN_SCHEMA:
+           case DO_PUBLICATION_TABLE_IN_SCHEMA:
            case DO_SUBSCRIPTION:
                /* Post-data objects: must come after the post-data boundary */
                addObjectDependency(dobj, postDataBound->dumpId);
index f9af14b7936158d9ad9b68f4abfc1daf5c20db98..d1d8608e9cc2d7b91e887eebd46a2fc23e22126b 100644 (file)
@@ -81,7 +81,7 @@ typedef enum
    DO_POLICY,
    DO_PUBLICATION,
    DO_PUBLICATION_REL,
-   DO_PUBLICATION_REL_IN_SCHEMA,
+   DO_PUBLICATION_TABLE_IN_SCHEMA,
    DO_SUBSCRIPTION
 } DumpableObjectType;
 
index 9901d9e0ba5f060404144d296505e9aa4295ef64..410d1790ee1ba87096faf355cf15a8ef2d8500b5 100644 (file)
@@ -82,7 +82,7 @@ enum dbObjectTypePriorities
    PRIO_POLICY,
    PRIO_PUBLICATION,
    PRIO_PUBLICATION_REL,
-   PRIO_PUBLICATION_REL_IN_SCHEMA,
+   PRIO_PUBLICATION_TABLE_IN_SCHEMA,
    PRIO_SUBSCRIPTION,
    PRIO_DEFAULT_ACL,           /* done in ACL pass */
    PRIO_EVENT_TRIGGER,         /* must be next to last! */
@@ -136,7 +136,7 @@ static const int dbObjectTypePriority[] =
    PRIO_POLICY,                /* DO_POLICY */
    PRIO_PUBLICATION,           /* DO_PUBLICATION */
    PRIO_PUBLICATION_REL,       /* DO_PUBLICATION_REL */
-   PRIO_PUBLICATION_REL_IN_SCHEMA, /* DO_PUBLICATION_REL_IN_SCHEMA */
+   PRIO_PUBLICATION_TABLE_IN_SCHEMA,   /* DO_PUBLICATION_TABLE_IN_SCHEMA */
    PRIO_SUBSCRIPTION           /* DO_SUBSCRIPTION */
 };
 
@@ -1479,7 +1479,7 @@ describeDumpableObject(DumpableObject *obj, char *buf, int bufsize)
                     "PUBLICATION TABLE (ID %d OID %u)",
                     obj->dumpId, obj->catId.oid);
            return;
-       case DO_PUBLICATION_REL_IN_SCHEMA:
+       case DO_PUBLICATION_TABLE_IN_SCHEMA:
            snprintf(buf, bufsize,
                     "PUBLICATION TABLES IN SCHEMA (ID %d OID %u)",
                     obj->dumpId, obj->catId.oid);
index 006661412eabad5b66035e37d687b4fe6667061b..ea721d963a7274ccb5d03d8f33689293d70091ba 100644 (file)
@@ -3162,7 +3162,7 @@ describeOneTableDetails(const char *schemaname,
                                  "UNION\n"
                                  "SELECT pubname\n"
                                  "FROM pg_catalog.pg_publication p\n"
-                                 "WHERE puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n"
+                                 "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n"
                                  "ORDER BY 1;",
                                  oid, oid, oid, oid);
            }
index 49123e28a4745d502f2c8bf8bd09e6a0fc9fe027..067138e6b59409b6bf4856fc319aa934e3102195 100644 (file)
@@ -3649,8 +3649,9 @@ typedef struct PublicationTable
 typedef enum PublicationObjSpecType
 {
    PUBLICATIONOBJ_TABLE,       /* Table type */
-   PUBLICATIONOBJ_REL_IN_SCHEMA,   /* Relations in schema type */
-   PUBLICATIONOBJ_CURRSCHEMA,  /* Get the first element from search_path */
+   PUBLICATIONOBJ_TABLE_IN_SCHEMA, /* Tables in schema type */
+   PUBLICATIONOBJ_TABLE_IN_CUR_SCHEMA, /* Get the first element from
+                                        * search_path */
    PUBLICATIONOBJ_CONTINUATION /* Continuation of previous type */
 } PublicationObjSpecType;
 
index 0f4fe4db8f113fa53eabfa26f9ac52e63ef9362c..2ff21a754343af10af7136c35a7c4268a321a051 100644 (file)
@@ -478,7 +478,7 @@ RESET SEARCH_PATH;
 -- check create publication on CURRENT_SCHEMA where TABLE/ALL TABLES in SCHEMA
 -- is not specified
 CREATE PUBLICATION testpub_forschema1 FOR CURRENT_SCHEMA;
-ERROR:  FOR TABLE/FOR ALL TABLES IN SCHEMA should be specified before the table/schema name(s)
+ERROR:  TABLE/ALL TABLES IN SCHEMA should be specified before the table/schema name(s)
 LINE 1: CREATE PUBLICATION testpub_forschema1 FOR CURRENT_SCHEMA;
                                                   ^
 -- check create publication on CURRENT_SCHEMA along with FOR TABLE
@@ -747,7 +747,7 @@ Tables from schemas:
 -- fail specifying table without any of 'FOR ALL TABLES IN SCHEMA' or
 --'FOR TABLE' or 'FOR ALL TABLES'
 CREATE PUBLICATION testpub_error FOR pub_test2.tbl1;
-ERROR:  FOR TABLE/FOR ALL TABLES IN SCHEMA should be specified before the table/schema name(s)
+ERROR:  TABLE/ALL TABLES IN SCHEMA should be specified before the table/schema name(s)
 LINE 1: CREATE PUBLICATION testpub_error FOR pub_test2.tbl1;
                                              ^
 DROP VIEW testpub_view;