From 073ce405d68355eed36a11b41e558232ecf18201 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Thu, 18 May 2017 14:16:16 -0400 Subject: Fix table syncing with different column order Logical replication supports replicating between tables with different column order. But this failed for the initial table sync because of a logic error in how the column list for the internal COPY command was composed. Fix that and also add a test. Also fix a minor omission in the column name mapping cache. When creating the mapping list, it would not skip locally dropped columns. So if a remote column had the same name as a locally dropped column (...pg.dropped...), then the expected error would not occur. --- src/backend/replication/logical/tablesync.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) (limited to 'src/backend/replication/logical/tablesync.c') diff --git a/src/backend/replication/logical/tablesync.c b/src/backend/replication/logical/tablesync.c index d69fc7086d0..fe45fb88203 100644 --- a/src/backend/replication/logical/tablesync.c +++ b/src/backend/replication/logical/tablesync.c @@ -492,25 +492,15 @@ static List * make_copy_attnamelist(LogicalRepRelMapEntry *rel) { List *attnamelist = NIL; - TupleDesc desc = RelationGetDescr(rel->localrel); int i; - for (i = 0; i < desc->natts; i++) + for (i = 0; i < rel->remoterel.natts; i++) { - int remoteattnum = rel->attrmap[i]; - - /* Skip dropped attributes. */ - if (desc->attrs[i]->attisdropped) - continue; - - /* Skip attributes that are missing on remote side. */ - if (remoteattnum < 0) - continue; - attnamelist = lappend(attnamelist, - makeString(rel->remoterel.attnames[remoteattnum])); + makeString(rel->remoterel.attnames[i])); } + return attnamelist; } -- cgit v1.2.3