From 1fe33252a08c285de9e84615cfde0569b9a75e58 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Mon, 17 Apr 2017 09:14:22 -0400
Subject: [PATCH] Document that ONLY can be specified in publication commands

Author: Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
---
 doc/src/sgml/ref/alter_publication.sgml   | 12 ++++++++----
 doc/src/sgml/ref/create_publication.sgml  |  9 +++++++--
 src/test/regress/expected/publication.out | 23 +++++++++++++++++++++++
 src/test/regress/sql/publication.sql      | 10 ++++++++++
 4 files changed, 48 insertions(+), 6 deletions(-)

diff --git a/doc/src/sgml/ref/alter_publication.sgml b/doc/src/sgml/ref/alter_publication.sgml
index 0a965b3bbf8..858231fbcbf 100644
--- a/doc/src/sgml/ref/alter_publication.sgml
+++ b/doc/src/sgml/ref/alter_publication.sgml
@@ -31,9 +31,9 @@ ALTER PUBLICATION <replaceable class="PARAMETER">name</replaceable> WITH ( <repl
 
 ALTER PUBLICATION <replaceable class="PARAMETER">name</replaceable> OWNER TO { <replaceable>new_owner</replaceable> | CURRENT_USER | SESSION_USER }
 ALTER PUBLICATION <replaceable class="PARAMETER">name</replaceable> RENAME TO <replaceable>new_name</replaceable>
-ALTER PUBLICATION <replaceable class="PARAMETER">name</replaceable> ADD TABLE <replaceable class="PARAMETER">table_name</replaceable> [, ...]
-ALTER PUBLICATION <replaceable class="PARAMETER">name</replaceable> SET TABLE <replaceable class="PARAMETER">table_name</replaceable> [, ...]
-ALTER PUBLICATION <replaceable class="PARAMETER">name</replaceable> DROP TABLE <replaceable class="PARAMETER">table_name</replaceable> [, ...]
+ALTER PUBLICATION <replaceable class="PARAMETER">name</replaceable> ADD TABLE [ ONLY ] <replaceable class="PARAMETER">table_name</replaceable> [ * ] [, ...]
+ALTER PUBLICATION <replaceable class="PARAMETER">name</replaceable> SET TABLE [ ONLY ] <replaceable class="PARAMETER">table_name</replaceable> [ * ] [, ...]
+ALTER PUBLICATION <replaceable class="PARAMETER">name</replaceable> DROP TABLE [ ONLY ] <replaceable class="PARAMETER">table_name</replaceable> [ * ] [, ...]
 </synopsis>
  </refsynopsisdiv>
 
@@ -116,7 +116,11 @@ ALTER PUBLICATION <replaceable class="PARAMETER">name</replaceable> DROP TABLE <
     <term><replaceable class="parameter">table_name</replaceable></term>
     <listitem>
      <para>
-      Name of an existing table.
+      Name of an existing table.  If <literal>ONLY</> is specified before the
+      table name, only that table is affected.  If <literal>ONLY</> is not
+      specified, the table and all its descendant tables (if any) are
+      affected.  Optionally, <literal>*</> can be specified after the table
+      name to explicitly indicate that descendant tables are included.
      </para>
     </listitem>
    </varlistentry>
diff --git a/doc/src/sgml/ref/create_publication.sgml b/doc/src/sgml/ref/create_publication.sgml
index 3cdde801fa1..0369b579c5c 100644
--- a/doc/src/sgml/ref/create_publication.sgml
+++ b/doc/src/sgml/ref/create_publication.sgml
@@ -22,7 +22,7 @@ PostgreSQL documentation
  <refsynopsisdiv>
 <synopsis>
 CREATE PUBLICATION <replaceable class="parameter">name</replaceable>
-    [ FOR TABLE <replaceable class="parameter">table_name</replaceable> [, ...]
+    [ FOR TABLE [ ONLY ] <replaceable class="parameter">table_name</replaceable> [ * ] [, ...]
       | FOR ALL TABLES ]
     [ WITH ( <replaceable class="parameter">option</replaceable> [, ... ] ) ]
 
@@ -68,7 +68,12 @@ CREATE PUBLICATION <replaceable class="parameter">name</replaceable>
     <term><literal>FOR TABLE</literal></term>
     <listitem>
      <para>
-      Specifies a list of tables to add to the publication.
+      Specifies a list of tables to add to the publication.  If
+      <literal>ONLY</> is specified before the table name, only
+      that table is added to the publication.  If <literal>ONLY</> is not
+      specified, the table and all its descendant tables (if any) are added.
+      Optionally, <literal>*</> can be specified after the table name to
+      explicitly indicate that descendant tables are included.
      </para>
     </listitem>
    </varlistentry>
diff --git a/src/test/regress/expected/publication.out b/src/test/regress/expected/publication.out
index 0964718a60e..5b7fb674dad 100644
--- a/src/test/regress/expected/publication.out
+++ b/src/test/regress/expected/publication.out
@@ -71,6 +71,29 @@ Publications:
 
 DROP TABLE testpub_tbl2;
 DROP PUBLICATION testpub_foralltables;
+CREATE TABLE testpub_tbl3 (a int);
+CREATE TABLE testpub_tbl3a (b text) INHERITS (testpub_tbl3);
+CREATE PUBLICATION testpub3 FOR TABLE testpub_tbl3;
+CREATE PUBLICATION testpub4 FOR TABLE ONLY testpub_tbl3;
+\dRp+ testpub3
+    Publication testpub3
+ Inserts | Updates | Deletes 
+---------+---------+---------
+ t       | t       | t
+Tables:
+    "public.testpub_tbl3"
+    "public.testpub_tbl3a"
+
+\dRp+ testpub4
+    Publication testpub4
+ Inserts | Updates | Deletes 
+---------+---------+---------
+ t       | t       | t
+Tables:
+    "public.testpub_tbl3"
+
+DROP TABLE testpub_tbl3, testpub_tbl3a;
+DROP PUBLICATION testpub3, testpub4;
 -- fail - view
 CREATE PUBLICATION testpub_fortbl FOR TABLE testpub_view;
 ERROR:  "testpub_view" is not a table
diff --git a/src/test/regress/sql/publication.sql b/src/test/regress/sql/publication.sql
index 85530bec0e7..b118bc9906f 100644
--- a/src/test/regress/sql/publication.sql
+++ b/src/test/regress/sql/publication.sql
@@ -44,6 +44,16 @@ SELECT pubname, puballtables FROM pg_publication WHERE pubname = 'testpub_forall
 DROP TABLE testpub_tbl2;
 DROP PUBLICATION testpub_foralltables;
 
+CREATE TABLE testpub_tbl3 (a int);
+CREATE TABLE testpub_tbl3a (b text) INHERITS (testpub_tbl3);
+CREATE PUBLICATION testpub3 FOR TABLE testpub_tbl3;
+CREATE PUBLICATION testpub4 FOR TABLE ONLY testpub_tbl3;
+\dRp+ testpub3
+\dRp+ testpub4
+
+DROP TABLE testpub_tbl3, testpub_tbl3a;
+DROP PUBLICATION testpub3, testpub4;
+
 -- fail - view
 CREATE PUBLICATION testpub_fortbl FOR TABLE testpub_view;
 CREATE PUBLICATION testpub_fortbl FOR TABLE testpub_tbl1, pub_test.testpub_nopk;
-- 
GitLab