Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1b6da28

Browse files
author
Amit Kapila
committed
Fix the initial sync tables with no columns.
The copy command formed for initial sync was using parenthesis for tables with no columns leading to syntax error. This patch avoids adding parenthesis for such tables. Reported-by: Justin G Author: Vignesh C Reviewed-by: Peter Smith, Amit Kapila Backpatch-through: 15 Discussion: http://postgr.es/m/18203-df37fe354b626670@postgresql.org
1 parent 9bbdffa commit 1b6da28

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

src/backend/replication/logical/tablesync.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,22 +1111,30 @@ copy_table(Relation rel)
11111111
/* Regular table with no row filter */
11121112
if (lrel.relkind == RELKIND_RELATION && qual == NIL)
11131113
{
1114-
appendStringInfo(&cmd, "COPY %s (",
1114+
appendStringInfo(&cmd, "COPY %s",
11151115
quote_qualified_identifier(lrel.nspname, lrel.relname));
11161116

1117-
/*
1118-
* XXX Do we need to list the columns in all cases? Maybe we're
1119-
* replicating all columns?
1120-
*/
1121-
for (int i = 0; i < lrel.natts; i++)
1117+
/* If the table has columns, then specify the columns */
1118+
if (lrel.natts)
11221119
{
1123-
if (i > 0)
1124-
appendStringInfoString(&cmd, ", ");
1120+
appendStringInfoString(&cmd, " (");
11251121

1126-
appendStringInfoString(&cmd, quote_identifier(lrel.attnames[i]));
1122+
/*
1123+
* XXX Do we need to list the columns in all cases? Maybe we're
1124+
* replicating all columns?
1125+
*/
1126+
for (int i = 0; i < lrel.natts; i++)
1127+
{
1128+
if (i > 0)
1129+
appendStringInfoString(&cmd, ", ");
1130+
1131+
appendStringInfoString(&cmd, quote_identifier(lrel.attnames[i]));
1132+
}
1133+
1134+
appendStringInfoString(&cmd, ")");
11271135
}
11281136

1129-
appendStringInfoString(&cmd, ") TO STDOUT");
1137+
appendStringInfoString(&cmd, " TO STDOUT");
11301138
}
11311139
else
11321140
{

src/test/subscription/t/001_rep_changes.pl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@
5757
"CREATE INDEX idx_no_replidentity_index ON tab_no_replidentity_index(c1)"
5858
);
5959

60+
# Replicate the changes without columns
61+
$node_publisher->safe_psql('postgres', "CREATE TABLE tab_no_col()");
62+
$node_publisher->safe_psql('postgres',
63+
"INSERT INTO tab_no_col default VALUES");
64+
6065
# Setup structure on subscriber
6166
$node_subscriber->safe_psql('postgres', "CREATE TABLE tab_notrep (a int)");
6267
$node_subscriber->safe_psql('postgres', "CREATE TABLE tab_ins (a int)");
@@ -87,13 +92,16 @@
8792
"CREATE INDEX idx_no_replidentity_index ON tab_no_replidentity_index(c1)"
8893
);
8994

95+
# replication of the table without columns
96+
$node_subscriber->safe_psql('postgres', "CREATE TABLE tab_no_col()");
97+
9098
# Setup logical replication
9199
my $publisher_connstr = $node_publisher->connstr . ' dbname=postgres';
92100
$node_publisher->safe_psql('postgres', "CREATE PUBLICATION tap_pub");
93101
$node_publisher->safe_psql('postgres',
94102
"CREATE PUBLICATION tap_pub_ins_only WITH (publish = insert)");
95103
$node_publisher->safe_psql('postgres',
96-
"ALTER PUBLICATION tap_pub ADD TABLE tab_rep, tab_full, tab_full2, tab_mixed, tab_include, tab_nothing, tab_full_pk, tab_no_replidentity_index"
104+
"ALTER PUBLICATION tap_pub ADD TABLE tab_rep, tab_full, tab_full2, tab_mixed, tab_include, tab_nothing, tab_full_pk, tab_no_replidentity_index, tab_no_col"
97105
);
98106
$node_publisher->safe_psql('postgres',
99107
"ALTER PUBLICATION tap_pub_ins_only ADD TABLE tab_ins");
@@ -141,6 +149,9 @@
141149
$node_publisher->safe_psql('postgres',
142150
"INSERT INTO tab_no_replidentity_index VALUES(1)");
143151

152+
$node_publisher->safe_psql('postgres',
153+
"INSERT INTO tab_no_col default VALUES");
154+
144155
$node_publisher->wait_for_catchup('tap_sub');
145156

146157
$result = $node_subscriber->safe_psql('postgres',
@@ -169,6 +180,10 @@
169180
1,
170181
"value replicated to subscriber without replica identity index");
171182

183+
$result =
184+
$node_subscriber->safe_psql('postgres', "SELECT count(*) FROM tab_no_col");
185+
is($result, qq(2), 'check replicated changes for table having no columns');
186+
172187
# insert some duplicate rows
173188
$node_publisher->safe_psql('postgres',
174189
"INSERT INTO tab_full SELECT generate_series(1,10)");

0 commit comments

Comments
 (0)