Skip to content

Commit e59d428

Browse files
committed
Fixes in ALTER SUBSCRIPTION DROP PUBLICATION code
ALTER SUBSCRIPTION DROP PUBLICATION does not actually support copy_data option, so remove it from tab completion. Also, reword the error message that is thrown when all the publications from a subscription are specified to be dropped. Also, made few doc and cosmetic adjustments. Author: Vignesh C <vignesh21@gmail.com> Reviewed-by: Bharath Rupireddy <bharath.rupireddy@enterprisedb.com> Reviewed-by: Japin Li <japinli@hotmail.com> Discussion: https://www.postgresql.org/message-id/flat/CALDaNm21RwsDzs4xj14ApteAF7auyyomHNnp+NEL-sH8m-jMvQ@mail.gmail.com
1 parent 63e6d05 commit e59d428

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

doc/src/sgml/ref/alter_subscription.sgml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ PostgreSQL documentation
2222
<refsynopsisdiv>
2323
<synopsis>
2424
ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> CONNECTION '<replaceable>conninfo</replaceable>'
25-
ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> SET PUBLICATION <replaceable class="parameter">publication_name</replaceable> [, ...] [ WITH ( <replaceable class="parameter">set_publication_option</replaceable> [= <replaceable class="parameter">value</replaceable>] [, ... ] ) ]
26-
ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> ADD PUBLICATION <replaceable class="parameter">publication_name</replaceable> [, ...] [ WITH ( <replaceable class="parameter">set_publication_option</replaceable> [= <replaceable class="parameter">value</replaceable>] [, ... ] ) ]
27-
ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> DROP PUBLICATION <replaceable class="parameter">publication_name</replaceable> [, ...] [ WITH ( <replaceable class="parameter">set_publication_option</replaceable> [= <replaceable class="parameter">value</replaceable>] [, ... ] ) ]
25+
ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> SET PUBLICATION <replaceable class="parameter">publication_name</replaceable> [, ...] [ WITH ( <replaceable class="parameter">publication_option</replaceable> [= <replaceable class="parameter">value</replaceable>] [, ... ] ) ]
26+
ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> ADD PUBLICATION <replaceable class="parameter">publication_name</replaceable> [, ...] [ WITH ( <replaceable class="parameter">publication_option</replaceable> [= <replaceable class="parameter">value</replaceable>] [, ... ] ) ]
27+
ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> DROP PUBLICATION <replaceable class="parameter">publication_name</replaceable> [, ...] [ WITH ( <replaceable class="parameter">publication_option</replaceable> [= <replaceable class="parameter">value</replaceable>] [, ... ] ) ]
2828
ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> REFRESH PUBLICATION [ WITH ( <replaceable class="parameter">refresh_option</replaceable> [= <replaceable class="parameter">value</replaceable>] [, ... ] ) ]
2929
ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> ENABLE
3030
ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> DISABLE
@@ -102,17 +102,17 @@ ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> RENAME TO <
102102
<para>
103103
Changes the list of subscribed publications. <literal>SET</literal>
104104
replaces the entire list of publications with a new list,
105-
<literal>ADD</literal> adds additional publications,
106-
<literal>DROP</literal> removes publications from the list of
107-
publications. See <xref linkend="sql-createsubscription"/> for more
108-
information. By default, this command will also act like
105+
<literal>ADD</literal> adds additional publications to the list of
106+
publications, and <literal>DROP</literal> removes the publications from
107+
the list of publications. See <xref linkend="sql-createsubscription"/>
108+
for more information. By default, this command will also act like
109109
<literal>REFRESH PUBLICATION</literal>, except that in case of
110110
<literal>ADD</literal> or <literal>DROP</literal>, only the added or
111111
dropped publications are refreshed.
112112
</para>
113113

114114
<para>
115-
<replaceable>set_publication_option</replaceable> specifies additional
115+
<replaceable>publication_option</replaceable> specifies additional
116116
options for this operation. The supported options are:
117117

118118
<variablelist>
@@ -129,7 +129,8 @@ ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> RENAME TO <
129129
</variablelist>
130130

131131
Additionally, refresh options as described
132-
under <literal>REFRESH PUBLICATION</literal> may be specified.
132+
under <literal>REFRESH PUBLICATION</literal> may be specified,
133+
except in the case of <literal>DROP PUBLICATION</literal>.
133134
</para>
134135
</listitem>
135136
</varlistentry>

src/backend/commands/subscriptioncmds.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -953,8 +953,6 @@ AlterSubscription(AlterSubscriptionStmt *stmt, bool isTopLevel)
953953
bool refresh;
954954
List *publist;
955955

956-
publist = merge_publications(sub->publications, stmt->publication, isadd, stmt->subname);
957-
958956
parse_subscription_options(stmt->options,
959957
NULL, /* no "connect" */
960958
NULL, NULL, /* no "enabled" */
@@ -967,6 +965,8 @@ AlterSubscription(AlterSubscriptionStmt *stmt, bool isTopLevel)
967965
NULL, NULL, /* no "binary" */
968966
NULL, NULL); /* no "streaming" */
969967

968+
publist = merge_publications(sub->publications, stmt->publication, isadd, stmt->subname);
969+
970970
values[Anum_pg_subscription_subpublications - 1] =
971971
publicationListToArray(publist);
972972
replaces[Anum_pg_subscription_subpublications - 1] = true;
@@ -1676,7 +1676,7 @@ merge_publications(List *oldpublist, List *newpublist, bool addpub, const char *
16761676
if (!oldpublist)
16771677
ereport(ERROR,
16781678
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1679-
errmsg("subscription must contain at least one publication")));
1679+
errmsg("cannot drop all the publications from a subscription")));
16801680

16811681
return oldpublist;
16821682
}

src/bin/psql/tab-complete.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,10 +1675,14 @@ psql_completion(const char *text, int start, int end)
16751675
else if (HeadMatches("ALTER", "SUBSCRIPTION", MatchAny) &&
16761676
TailMatches("ADD|DROP|SET", "PUBLICATION", MatchAny))
16771677
COMPLETE_WITH("WITH (");
1678-
/* ALTER SUBSCRIPTION <name> ADD|DROP|SET PUBLICATION <name> WITH ( */
1678+
/* ALTER SUBSCRIPTION <name> ADD|SET PUBLICATION <name> WITH ( */
16791679
else if (HeadMatches("ALTER", "SUBSCRIPTION", MatchAny) &&
1680-
TailMatches("ADD|DROP|SET", "PUBLICATION", MatchAny, "WITH", "("))
1680+
TailMatches("ADD|SET", "PUBLICATION", MatchAny, "WITH", "("))
16811681
COMPLETE_WITH("copy_data", "refresh");
1682+
/* ALTER SUBSCRIPTION <name> DROP PUBLICATION <name> WITH ( */
1683+
else if (HeadMatches("ALTER", "SUBSCRIPTION", MatchAny) &&
1684+
TailMatches("DROP", "PUBLICATION", MatchAny, "WITH", "("))
1685+
COMPLETE_WITH("refresh");
16821686

16831687
/* ALTER SCHEMA <name> */
16841688
else if (Matches("ALTER", "SCHEMA", MatchAny))

src/test/regress/expected/subscription.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ ALTER SUBSCRIPTION regress_testsub DROP PUBLICATION testpub1, testpub1 WITH (ref
223223
ERROR: publication name "testpub1" used more than once
224224
-- fail - all publications are deleted
225225
ALTER SUBSCRIPTION regress_testsub DROP PUBLICATION testpub, testpub1, testpub2 WITH (refresh = false);
226-
ERROR: subscription must contain at least one publication
226+
ERROR: cannot drop all the publications from a subscription
227227
-- fail - publication does not exist in subscription
228228
ALTER SUBSCRIPTION regress_testsub DROP PUBLICATION testpub3 WITH (refresh = false);
229229
ERROR: publication "testpub3" is not in subscription "regress_testsub"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy