diff --git a/doc/src/sgml/ref/create_publication.sgml b/doc/src/sgml/ref/create_publication.sgml index 0c1b469..9891fef 100644 --- a/doc/src/sgml/ref/create_publication.sgml +++ b/doc/src/sgml/ref/create_publication.sgml @@ -122,16 +122,6 @@ CREATE PUBLICATION name - - FOR ALL SEQUENCES - - - Marks the publication as one that synchronizing changes for all sequences - in the database, including sequences created in the future. - - - - FOR ALL TABLES @@ -173,6 +163,16 @@ CREATE PUBLICATION name + + FOR ALL SEQUENCES + + + Marks the publication as one that synchronizes changes for all sequences + in the database, including sequences created in the future. + + + + WITH ( publication_parameter [= value] [, ... ] ) diff --git a/src/backend/commands/publicationcmds.c b/src/backend/commands/publicationcmds.c index 35c7dda..a2ccbf3 100644 --- a/src/backend/commands/publicationcmds.c +++ b/src/backend/commands/publicationcmds.c @@ -751,8 +751,9 @@ CreatePublication(ParseState *pstate, CreatePublicationStmt *stmt) if ((stmt->for_all_tables || stmt->for_all_sequences) && !superuser()) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("must be superuser to create FOR ALL %s publication", - stmt->for_all_tables ? "TABLES" : "SEQUENCES"))); + errmsg("must be superuser to create a %s publication", + stmt->for_all_tables ? "FOR ALL TABLES" : + "FOR ALL SEQUENCES"))); rel = table_open(PublicationRelationId, RowExclusiveLock); diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 382cf5c..760d700 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -10565,7 +10565,7 @@ AlterOwnerStmt: ALTER AGGREGATE aggregate_with_argtypes OWNER TO RoleSpec * pub_obj_type is one of: * * TABLES - * SCHEMAS + * SEQUENCES * * CREATE PUBLICATION FOR pub_obj [, ...] [WITH options] * @@ -10707,13 +10707,13 @@ AllPublicationObjSpec: TABLES { $$ = makeNode(AllPublicationObjSpec); - $$->pubobjtype = PUBLICATION_ALLTABLES; + $$->pubobjtype = PUBLICATION_ALL_TABLES; $$->location = @1; } | SEQUENCES { $$ = makeNode(AllPublicationObjSpec); - $$->pubobjtype = PUBLICATION_ALLSEQUENCES; + $$->pubobjtype = PUBLICATION_ALL_SEQUENCES; $$->location = @1; } ; @@ -19439,41 +19439,41 @@ parsePartitionStrategy(char *strategy) } /* - * Process allbjects_list to check if the options have been specified more than + * Process all_objects_list to check if the options have been specified more than * once and set alltables/allsequences. */ static void -preprocess_allpubobjtype_list(List *allbjects_list, bool *alltables, +preprocess_allpubobjtype_list(List *all_objects_list, bool *alltables, bool *allsequences, core_yyscan_t yyscanner) { bool alltables_specified = false; bool allsequences_specified = false; - if (!allbjects_list) + if (!all_objects_list) return; - foreach_ptr(AllPublicationObjSpec, allpubob, allbjects_list) + foreach_ptr(AllPublicationObjSpec, obj, all_objects_list) { - if (allpubob->pubobjtype == PUBLICATION_ALLTABLES) + if (obj->pubobjtype == PUBLICATION_ALL_TABLES) { if (alltables_specified) ereport(ERROR, errcode(ERRCODE_SYNTAX_ERROR), errmsg("invalid publication object list"), errdetail("TABLES can be specified only once."), - parser_errposition(allpubob->location)); + parser_errposition(obj->location)); alltables_specified = true; *alltables = true; } - else if (allpubob->pubobjtype == PUBLICATION_ALLSEQUENCES) + else if (obj->pubobjtype == PUBLICATION_ALL_SEQUENCES) { if (allsequences_specified) ereport(ERROR, errcode(ERRCODE_SYNTAX_ERROR), errmsg("invalid publication object list"), errdetail("SEQUENCES can be specified only once."), - parser_errposition(allpubob->location)); + parser_errposition(obj->location)); allsequences_specified = true; *allsequences = true; diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 0f55a1b..da713c2 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -4326,16 +4326,12 @@ dumpPublication(Archive *fout, const PublicationInfo *pubinfo) appendPQExpBuffer(query, "CREATE PUBLICATION %s", qpubname); - if (pubinfo->puballtables || pubinfo->puballsequences) - { - appendPQExpBufferStr(query, " FOR ALL"); - if (pubinfo->puballtables && pubinfo->puballsequences) - appendPQExpBufferStr(query, " TABLES, SEQUENCES"); - else if (pubinfo->puballtables) - appendPQExpBufferStr(query, " TABLES"); - else - appendPQExpBufferStr(query, " SEQUENCES"); - } + if (pubinfo->puballtables && pubinfo->puballsequences) + appendPQExpBufferStr(query, " FOR ALL TABLES, SEQUENCES"); + else if (pubinfo->puballtables) + appendPQExpBufferStr(query, " FOR ALL TABLES"); + else if (pubinfo->puballsequences) + appendPQExpBufferStr(query, " FOR ALL SEQUENCES"); appendPQExpBufferStr(query, " WITH (publish = '"); if (pubinfo->pubinsert) diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 1c50940..50efbe5 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -4167,8 +4167,8 @@ typedef struct PublicationObjSpec */ typedef enum AllPublicationObjType { - PUBLICATION_ALLTABLES, /* All tables */ - PUBLICATION_ALLSEQUENCES, /* All sequences */ + PUBLICATION_ALL_TABLES, /* All tables */ + PUBLICATION_ALL_SEQUENCES, /* All sequences */ } AllPublicationObjType; typedef struct AllPublicationObjSpec diff --git a/src/test/regress/expected/publication.out b/src/test/regress/expected/publication.out index 579c693..d0200d5 100644 --- a/src/test/regress/expected/publication.out +++ b/src/test/regress/expected/publication.out @@ -228,9 +228,10 @@ Tables: DROP TABLE testpub_tbl3, testpub_tbl3a; DROP PUBLICATION testpub3, testpub4; ---- sequences publication +--- Tests for publications with SEQUENCES CREATE SEQUENCE testpub_seq0; CREATE SEQUENCE pub_test.testpub_seq1; +-- FOR ALL SEQUENCES SET client_min_messages = 'ERROR'; CREATE PUBLICATION testpub_forallsequences FOR ALL SEQUENCES; RESET client_min_messages; @@ -255,7 +256,7 @@ Publications: regress_publication_user | f | t | t | t | t | t | f (1 row) ---- combination of all tables and all sequences publication +--- FOR ALL specifying both TABLES and SEQUENCES SET client_min_messages = 'ERROR'; CREATE PUBLICATION testpub_for_allsequences_alltables FOR ALL SEQUENCES, TABLES; RESET client_min_messages; @@ -275,13 +276,13 @@ SELECT pubname, puballtables, puballsequences FROM pg_publication WHERE pubname DROP SEQUENCE testpub_seq0, pub_test.testpub_seq1; DROP PUBLICATION testpub_forallsequences; DROP PUBLICATION testpub_for_allsequences_alltables; --- fail - specifying tables more than once; +-- fail - FOR ALL specifying TABLES more than once CREATE PUBLICATION testpub_for_allsequences_alltables FOR ALL SEQUENCES, TABLES, TABLES; ERROR: invalid publication object list LINE 1: ...or_allsequences_alltables FOR ALL SEQUENCES, TABLES, TABLES; ^ DETAIL: TABLES can be specified only once. --- fail - specifying sequences more than once; +-- fail - FOR ALL specifying SEQUENCES more than once CREATE PUBLICATION testpub_for_allsequences_alltables FOR ALL SEQUENCES, TABLES, SEQUENCES; ERROR: invalid publication object list LINE 1: ...allsequences_alltables FOR ALL SEQUENCES, TABLES, SEQUENCES; diff --git a/src/test/regress/sql/publication.sql b/src/test/regress/sql/publication.sql index ad0af9d..c28d554 100644 --- a/src/test/regress/sql/publication.sql +++ b/src/test/regress/sql/publication.sql @@ -117,10 +117,11 @@ RESET client_min_messages; DROP TABLE testpub_tbl3, testpub_tbl3a; DROP PUBLICATION testpub3, testpub4; ---- sequences publication +--- Tests for publications with SEQUENCES CREATE SEQUENCE testpub_seq0; CREATE SEQUENCE pub_test.testpub_seq1; +-- FOR ALL SEQUENCES SET client_min_messages = 'ERROR'; CREATE PUBLICATION testpub_forallsequences FOR ALL SEQUENCES; RESET client_min_messages; @@ -129,7 +130,7 @@ SELECT pubname, puballtables, puballsequences FROM pg_publication WHERE pubname \d+ pub_test.testpub_seq1 \dRp+ testpub_forallsequences ---- combination of all tables and all sequences publication +--- FOR ALL specifying both TABLES and SEQUENCES SET client_min_messages = 'ERROR'; CREATE PUBLICATION testpub_for_allsequences_alltables FOR ALL SEQUENCES, TABLES; RESET client_min_messages; @@ -141,10 +142,10 @@ DROP SEQUENCE testpub_seq0, pub_test.testpub_seq1; DROP PUBLICATION testpub_forallsequences; DROP PUBLICATION testpub_for_allsequences_alltables; --- fail - specifying tables more than once; +-- fail - FOR ALL specifying TABLES more than once CREATE PUBLICATION testpub_for_allsequences_alltables FOR ALL SEQUENCES, TABLES, TABLES; --- fail - specifying sequences more than once; +-- fail - FOR ALL specifying SEQUENCES more than once CREATE PUBLICATION testpub_for_allsequences_alltables FOR ALL SEQUENCES, TABLES, SEQUENCES; -- Tests for partitioned tables