1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-06 07:49:08 +03:00

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
This commit is contained in:
Amit Kapila
2023-11-22 11:14:35 +05:30
parent 4e64be6520
commit 57aae65aee
2 changed files with 34 additions and 11 deletions

View File

@@ -1043,22 +1043,30 @@ copy_table(Relation rel)
/* Regular table with no row filter */
if (lrel.relkind == RELKIND_RELATION && qual == NIL)
{
appendStringInfo(&cmd, "COPY %s (",
appendStringInfo(&cmd, "COPY %s",
quote_qualified_identifier(lrel.nspname, lrel.relname));
/*
* XXX Do we need to list the columns in all cases? Maybe we're
* replicating all columns?
*/
for (int i = 0; i < lrel.natts; i++)
/* If the table has columns, then specify the columns */
if (lrel.natts)
{
if (i > 0)
appendStringInfoString(&cmd, ", ");
appendStringInfoString(&cmd, " (");
appendStringInfoString(&cmd, quote_identifier(lrel.attnames[i]));
/*
* XXX Do we need to list the columns in all cases? Maybe we're
* replicating all columns?
*/
for (int i = 0; i < lrel.natts; i++)
{
if (i > 0)
appendStringInfoString(&cmd, ", ");
appendStringInfoString(&cmd, quote_identifier(lrel.attnames[i]));
}
appendStringInfoString(&cmd, ")");
}
appendStringInfo(&cmd, ") TO STDOUT");
appendStringInfo(&cmd, " TO STDOUT");
}
else
{