@@ -1784,6 +1784,152 @@ test_sub=# SELECT * from tab_gen_to_gen;
1784
1784
the publisher.
1785
1785
</para>
1786
1786
</note>
1787
+
1788
+ <sect2 id="logical-replication-gencols-examples">
1789
+ <title>Examples</title>
1790
+
1791
+ <para>
1792
+ Setup the publisher and subscriber tables. Note that the subscriber
1793
+ table columns have same names, but are not defined the same as the
1794
+ publisher columns.
1795
+ <programlisting>
1796
+ test_pub=# CREATE TABLE t1 (
1797
+ a int PRIMARY KEY,
1798
+ b int,
1799
+ c int GENERATED ALWAYS AS (a + 1) STORED,
1800
+ d int GENERATED ALWAYS AS (b + 1) STORED);
1801
+
1802
+ test_pub=# CREATE TABLE t2 (
1803
+ a int PRIMARY KEY,
1804
+ b int,
1805
+ c int GENERATED ALWAYS AS (a + 1) STORED,
1806
+ d int GENERATED ALWAYS AS (b + 1) STORED);
1807
+ </programlisting>
1808
+
1809
+ <programlisting>
1810
+ test_sub=# CREATE TABLE t1 (
1811
+ a int PRIMARY KEY,
1812
+ b int,
1813
+ c int,
1814
+ d int GENERATED ALWAYS AS (b * 100) STORED);
1815
+
1816
+ test_sub=# CREATE TABLE t2 (
1817
+ a int PRIMARY KEY,
1818
+ b int,
1819
+ c int,
1820
+ d int);
1821
+ </programlisting>
1822
+ </para>
1823
+
1824
+ <para>
1825
+ Create the <literal>PUBLICATION</literal> and the <literal>SUBSCRIPTION</literal>.
1826
+ Note that the publication specifies a column list for table <literal>t2</literal>.
1827
+ The publication also sets parameter <literal>publish_generated_columns=none</literal>,
1828
+ but that is just for demonstration because <literal>none</literal> is the
1829
+ default anyway.
1830
+ <programlisting>
1831
+ test_pub=# CREATE PUBLICATION pub1 FOR TABLE t1, t2(a,c)
1832
+ WITH (publish_generated_columns=none);
1833
+ </programlisting>
1834
+
1835
+ <programlisting>
1836
+ test_sub=# CREATE SUBSCRIPTION sub1
1837
+ CONNECTION 'dbname=test_pub'
1838
+ PUBLICATION pub1;
1839
+ </programlisting>
1840
+ </para>
1841
+
1842
+ <para>
1843
+ Insert some data to the publisher tables:
1844
+ <programlisting>
1845
+ test_pub=# INSERT INTO t1 VALUES (1,2);
1846
+ INSERT 0 1
1847
+ test_pub=# INSERT INTO t2 VALUES (1,2);
1848
+ INSERT 0 1
1849
+
1850
+ test_pub=# SELECT * FROM t1;
1851
+ a | b | c | d
1852
+ ---+---+---+---
1853
+ 1 | 2 | 2 | 3
1854
+ (1 row)
1855
+
1856
+ test_pub=# SELECT * FROM t2;
1857
+ a | b | c | d
1858
+ ---+---+---+---
1859
+ 1 | 2 | 2 | 3
1860
+ (1 row)
1861
+ </programlisting>
1862
+ </para>
1863
+
1864
+ <para>
1865
+ Observe how columns for table <literal>t1</literal> were replicated:
1866
+ <programlisting>
1867
+ test_sub=# SELECT * FROM t1;
1868
+ a | b | c | d
1869
+ ---+---+---+-----
1870
+ 1 | 2 | | 200
1871
+ (1 row)
1872
+ </programlisting>
1873
+ <itemizedlist>
1874
+ <listitem><para>
1875
+ <literal>t1.a</literal> is a regular column. It gets replicated normally.
1876
+ </para></listitem>
1877
+
1878
+ <listitem><para>
1879
+ <literal>t1.b</literal> is a regular column. It gets replicated normally.
1880
+ </para></listitem>
1881
+
1882
+ <listitem><para>
1883
+ <literal>t1.c</literal> is a generated column. It is not replicated because
1884
+ <literal>publish_generated_columns=none</literal>. The subscriber
1885
+ <literal>t2.c</literal> default column value is used.
1886
+ </para></listitem>
1887
+
1888
+ <listitem><para>
1889
+ <literal>t1.d</literal> is a generated column. It is not replicated because
1890
+ <literal>publish_generated_columns=none</literal>. The subscriber
1891
+ <literal>t2.d</literal> generated column value is used.
1892
+ </para></listitem>
1893
+ </itemizedlist>
1894
+ </para>
1895
+
1896
+ <para>
1897
+ Observe how columns for table <literal>t2</literal> were replicated.
1898
+ <programlisting>
1899
+ test_sub=# SELECT * FROM t2;
1900
+ a | b | c | d
1901
+ ---+---+---+---
1902
+ 1 | | 2 |
1903
+ (1 row)
1904
+ </programlisting>
1905
+ <itemizedlist>
1906
+ <listitem><para>
1907
+ <literal>t2.a</literal> is a regular column. It was specified in the column
1908
+ list, so is replicated normally.
1909
+ </para></listitem>
1910
+
1911
+ <listitem><para>
1912
+ <literal>t2.b</literal> is a regular column. It was not specified in column
1913
+ list so is not replicated. The subscriber <literal>t2.b</literal> default
1914
+ value is used.
1915
+ </para></listitem>
1916
+
1917
+ <listitem><para>
1918
+ <literal>t2.c</literal> is a generated column. It was specified in the
1919
+ column list, so is replicated to the subscriber <literal>t2.c</literal>
1920
+ regular column.
1921
+ </para></listitem>
1922
+
1923
+ <listitem><para>
1924
+ <literal>t2.d</literal> is a generated column. It was not specified in the
1925
+ column list, so is not replicated. The subscriber <literal>t2.d</literal>
1926
+ default value is used.
1927
+ </para></listitem>
1928
+ </itemizedlist>
1929
+ </para>
1930
+
1931
+ </sect2>
1932
+
1787
1933
</sect1>
1788
1934
1789
1935
<sect1 id="logical-replication-conflicts">
0 commit comments