Skip to content

Commit b3812d0

Browse files
author
Amit Kapila
committed
Rename some enums to use TABLE instead of REL.
Commit 5a28324 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
1 parent 57b5a96 commit b3812d0

File tree

8 files changed

+24
-23
lines changed

8 files changed

+24
-23
lines changed

src/backend/commands/publicationcmds.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,13 @@ ObjectsInPublicationToOids(List *pubobjspec_list, ParseState *pstate,
169169
case PUBLICATIONOBJ_TABLE:
170170
*rels = lappend(*rels, pubobj->pubtable);
171171
break;
172-
case PUBLICATIONOBJ_REL_IN_SCHEMA:
172+
case PUBLICATIONOBJ_TABLE_IN_SCHEMA:
173173
schemaid = get_namespace_oid(pubobj->name, false);
174174

175175
/* Filter out duplicates if user specifies "sch1, sch1" */
176176
*schemas = list_append_unique_oid(*schemas, schemaid);
177177
break;
178-
case PUBLICATIONOBJ_CURRSCHEMA:
178+
case PUBLICATIONOBJ_TABLE_IN_CUR_SCHEMA:
179179
search_path = fetch_search_path(false);
180180
if (search_path == NIL) /* nothing valid in search_path? */
181181
ereport(ERROR,
@@ -214,7 +214,7 @@ CheckObjSchemaNotAlreadyInPublication(List *rels, List *schemaidlist,
214214

215215
if (list_member_oid(schemaidlist, relSchemaId))
216216
{
217-
if (checkobjtype == PUBLICATIONOBJ_REL_IN_SCHEMA)
217+
if (checkobjtype == PUBLICATIONOBJ_TABLE_IN_SCHEMA)
218218
ereport(ERROR,
219219
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
220220
errmsg("cannot add schema \"%s\" to publication",
@@ -613,7 +613,7 @@ AlterPublicationSchemas(AlterPublicationStmt *stmt,
613613
rels = OpenReliIdList(reloids);
614614

615615
CheckObjSchemaNotAlreadyInPublication(rels, schemaidlist,
616-
PUBLICATIONOBJ_REL_IN_SCHEMA);
616+
PUBLICATIONOBJ_TABLE_IN_SCHEMA);
617617

618618
CloseTableList(rels);
619619
PublicationAddSchemas(pubform->oid, schemaidlist, false, stmt);

src/backend/parser/gram.y

+7-7
Original file line numberDiff line numberDiff line change
@@ -9662,14 +9662,14 @@ PublicationObjSpec:
96629662
| ALL TABLES IN_P SCHEMA ColId
96639663
{
96649664
$$ = makeNode(PublicationObjSpec);
9665-
$$->pubobjtype = PUBLICATIONOBJ_REL_IN_SCHEMA;
9665+
$$->pubobjtype = PUBLICATIONOBJ_TABLE_IN_SCHEMA;
96669666
$$->name = $5;
96679667
$$->location = @5;
96689668
}
96699669
| ALL TABLES IN_P SCHEMA CURRENT_SCHEMA
96709670
{
96719671
$$ = makeNode(PublicationObjSpec);
9672-
$$->pubobjtype = PUBLICATIONOBJ_CURRSCHEMA;
9672+
$$->pubobjtype = PUBLICATIONOBJ_TABLE_IN_CUR_SCHEMA;
96739673
$$->location = @5;
96749674
}
96759675
| ColId
@@ -17323,7 +17323,7 @@ preprocess_pubobj_list(List *pubobjspec_list, core_yyscan_t yyscanner)
1732317323
if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
1732417324
ereport(ERROR,
1732517325
errcode(ERRCODE_SYNTAX_ERROR),
17326-
errmsg("FOR TABLE/FOR ALL TABLES IN SCHEMA should be specified before the table/schema name(s)"),
17326+
errmsg("TABLE/ALL TABLES IN SCHEMA should be specified before the table/schema name(s)"),
1732717327
parser_errposition(pubobj->location));
1732817328

1732917329
foreach(cell, pubobjspec_list)
@@ -17351,17 +17351,17 @@ preprocess_pubobj_list(List *pubobjspec_list, core_yyscan_t yyscanner)
1735117351
pubobj->name = NULL;
1735217352
}
1735317353
}
17354-
else if (pubobj->pubobjtype == PUBLICATIONOBJ_REL_IN_SCHEMA ||
17355-
pubobj->pubobjtype == PUBLICATIONOBJ_CURRSCHEMA)
17354+
else if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLE_IN_SCHEMA ||
17355+
pubobj->pubobjtype == PUBLICATIONOBJ_TABLE_IN_CUR_SCHEMA)
1735617356
{
1735717357
/*
1735817358
* We can distinguish between the different type of schema
1735917359
* objects based on whether name and pubtable is set.
1736017360
*/
1736117361
if (pubobj->name)
17362-
pubobj->pubobjtype = PUBLICATIONOBJ_REL_IN_SCHEMA;
17362+
pubobj->pubobjtype = PUBLICATIONOBJ_TABLE_IN_SCHEMA;
1736317363
else if (!pubobj->name && !pubobj->pubtable)
17364-
pubobj->pubobjtype = PUBLICATIONOBJ_CURRSCHEMA;
17364+
pubobj->pubobjtype = PUBLICATIONOBJ_TABLE_IN_CUR_SCHEMA;
1736517365
else
1736617366
ereport(ERROR,
1736717367
errcode(ERRCODE_SYNTAX_ERROR),

src/bin/pg_dump/pg_dump.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -4194,7 +4194,7 @@ getPublicationNamespaces(Archive *fout)
41944194
continue;
41954195

41964196
/* OK, make a DumpableObject for this relationship */
4197-
pubsinfo[j].dobj.objType = DO_PUBLICATION_REL_IN_SCHEMA;
4197+
pubsinfo[j].dobj.objType = DO_PUBLICATION_TABLE_IN_SCHEMA;
41984198
pubsinfo[j].dobj.catId.tableoid =
41994199
atooid(PQgetvalue(res, i, i_tableoid));
42004200
pubsinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
@@ -10331,7 +10331,7 @@ dumpDumpableObject(Archive *fout, const DumpableObject *dobj)
1033110331
case DO_PUBLICATION_REL:
1033210332
dumpPublicationTable(fout, (const PublicationRelInfo *) dobj);
1033310333
break;
10334-
case DO_PUBLICATION_REL_IN_SCHEMA:
10334+
case DO_PUBLICATION_TABLE_IN_SCHEMA:
1033510335
dumpPublicationNamespace(fout,
1033610336
(const PublicationSchemaInfo *) dobj);
1033710337
break;
@@ -18559,7 +18559,7 @@ addBoundaryDependencies(DumpableObject **dobjs, int numObjs,
1855918559
case DO_POLICY:
1856018560
case DO_PUBLICATION:
1856118561
case DO_PUBLICATION_REL:
18562-
case DO_PUBLICATION_REL_IN_SCHEMA:
18562+
case DO_PUBLICATION_TABLE_IN_SCHEMA:
1856318563
case DO_SUBSCRIPTION:
1856418564
/* Post-data objects: must come after the post-data boundary */
1856518565
addObjectDependency(dobj, postDataBound->dumpId);

src/bin/pg_dump/pg_dump.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ typedef enum
8181
DO_POLICY,
8282
DO_PUBLICATION,
8383
DO_PUBLICATION_REL,
84-
DO_PUBLICATION_REL_IN_SCHEMA,
84+
DO_PUBLICATION_TABLE_IN_SCHEMA,
8585
DO_SUBSCRIPTION
8686
} DumpableObjectType;
8787

src/bin/pg_dump/pg_dump_sort.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ enum dbObjectTypePriorities
8282
PRIO_POLICY,
8383
PRIO_PUBLICATION,
8484
PRIO_PUBLICATION_REL,
85-
PRIO_PUBLICATION_REL_IN_SCHEMA,
85+
PRIO_PUBLICATION_TABLE_IN_SCHEMA,
8686
PRIO_SUBSCRIPTION,
8787
PRIO_DEFAULT_ACL, /* done in ACL pass */
8888
PRIO_EVENT_TRIGGER, /* must be next to last! */
@@ -136,7 +136,7 @@ static const int dbObjectTypePriority[] =
136136
PRIO_POLICY, /* DO_POLICY */
137137
PRIO_PUBLICATION, /* DO_PUBLICATION */
138138
PRIO_PUBLICATION_REL, /* DO_PUBLICATION_REL */
139-
PRIO_PUBLICATION_REL_IN_SCHEMA, /* DO_PUBLICATION_REL_IN_SCHEMA */
139+
PRIO_PUBLICATION_TABLE_IN_SCHEMA, /* DO_PUBLICATION_TABLE_IN_SCHEMA */
140140
PRIO_SUBSCRIPTION /* DO_SUBSCRIPTION */
141141
};
142142

@@ -1479,7 +1479,7 @@ describeDumpableObject(DumpableObject *obj, char *buf, int bufsize)
14791479
"PUBLICATION TABLE (ID %d OID %u)",
14801480
obj->dumpId, obj->catId.oid);
14811481
return;
1482-
case DO_PUBLICATION_REL_IN_SCHEMA:
1482+
case DO_PUBLICATION_TABLE_IN_SCHEMA:
14831483
snprintf(buf, bufsize,
14841484
"PUBLICATION TABLES IN SCHEMA (ID %d OID %u)",
14851485
obj->dumpId, obj->catId.oid);

src/bin/psql/describe.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3162,7 +3162,7 @@ describeOneTableDetails(const char *schemaname,
31623162
"UNION\n"
31633163
"SELECT pubname\n"
31643164
"FROM pg_catalog.pg_publication p\n"
3165-
"WHERE puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n"
3165+
"WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n"
31663166
"ORDER BY 1;",
31673167
oid, oid, oid, oid);
31683168
}

src/include/nodes/parsenodes.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -3649,8 +3649,9 @@ typedef struct PublicationTable
36493649
typedef enum PublicationObjSpecType
36503650
{
36513651
PUBLICATIONOBJ_TABLE, /* Table type */
3652-
PUBLICATIONOBJ_REL_IN_SCHEMA, /* Relations in schema type */
3653-
PUBLICATIONOBJ_CURRSCHEMA, /* Get the first element from search_path */
3652+
PUBLICATIONOBJ_TABLE_IN_SCHEMA, /* Tables in schema type */
3653+
PUBLICATIONOBJ_TABLE_IN_CUR_SCHEMA, /* Get the first element from
3654+
* search_path */
36543655
PUBLICATIONOBJ_CONTINUATION /* Continuation of previous type */
36553656
} PublicationObjSpecType;
36563657

src/test/regress/expected/publication.out

+2-2
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ RESET SEARCH_PATH;
478478
-- check create publication on CURRENT_SCHEMA where TABLE/ALL TABLES in SCHEMA
479479
-- is not specified
480480
CREATE PUBLICATION testpub_forschema1 FOR CURRENT_SCHEMA;
481-
ERROR: FOR TABLE/FOR ALL TABLES IN SCHEMA should be specified before the table/schema name(s)
481+
ERROR: TABLE/ALL TABLES IN SCHEMA should be specified before the table/schema name(s)
482482
LINE 1: CREATE PUBLICATION testpub_forschema1 FOR CURRENT_SCHEMA;
483483
^
484484
-- check create publication on CURRENT_SCHEMA along with FOR TABLE
@@ -747,7 +747,7 @@ Tables from schemas:
747747
-- fail specifying table without any of 'FOR ALL TABLES IN SCHEMA' or
748748
--'FOR TABLE' or 'FOR ALL TABLES'
749749
CREATE PUBLICATION testpub_error FOR pub_test2.tbl1;
750-
ERROR: FOR TABLE/FOR ALL TABLES IN SCHEMA should be specified before the table/schema name(s)
750+
ERROR: TABLE/ALL TABLES IN SCHEMA should be specified before the table/schema name(s)
751751
LINE 1: CREATE PUBLICATION testpub_error FOR pub_test2.tbl1;
752752
^
753753
DROP VIEW testpub_view;

0 commit comments

Comments
 (0)