diff --git a/src/backend/replication/logical/tablesync.c b/src/backend/replication/logical/tablesync.c index 0fbf661..ddeb6a8 100644 --- a/src/backend/replication/logical/tablesync.c +++ b/src/backend/replication/logical/tablesync.c @@ -694,7 +694,7 @@ process_syncing_tables(XLogRecPtr current_lsn) /* * Create list of columns for COPY based on logical relation mapping. Do not - * include generated columns, of the subscription table, in the column list. + * include generated columns of the subscription table in the column list. */ static List * make_copy_attnamelist(LogicalRepRelMapEntry *rel, bool *attgenlist) @@ -706,6 +706,7 @@ make_copy_attnamelist(LogicalRepRelMapEntry *rel, bool *attgenlist) desc = RelationGetDescr(rel->localrel); gencollist = palloc0(MaxTupleAttributeNumber * sizeof(bool)); + /* Loop to handle subscription table generated columns. */ for (int i = 0; i < desc->natts; i++) { int attnum; @@ -716,23 +717,25 @@ make_copy_attnamelist(LogicalRepRelMapEntry *rel, bool *attgenlist) attnum = logicalrep_rel_att_by_name(&rel->remoterel, NameStr(attr->attname)); - - /* - * Check if subscription table have a generated column with same - * column name as a non-generated column in the corresponding - * publication table. - * 'gencollist' stores column if it is a generated column in - * subscription table. We should not include this column in column - * list for COPY. - */ if (attnum >= 0) { + /* + * Check if the subscription table generated column has same + * name as a non-generated column in the corresponding + * publication table. + */ if(!attgenlist[attnum]) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("logical replication target relation \"%s.%s\" has a generated column \"%s\" " "but corresponding column on source relation is not a generated column", rel->remoterel.nspname, rel->remoterel.relname, NameStr(attr->attname)))); + + /* + * 'gencollist' records that this is a generated column in + * the subscription table. Later, we use this information to + * skip adding this column to the column list for COPY. + */ gencollist[attnum] = true; } }