diff --git a/src/backend/distributed/commands/create_distributed_table.c b/src/backend/distributed/commands/create_distributed_table.c index 0e5c1edd4..432279b1d 100644 --- a/src/backend/distributed/commands/create_distributed_table.c +++ b/src/backend/distributed/commands/create_distributed_table.c @@ -1368,7 +1368,11 @@ TupleDescColumnNameList(TupleDesc tupleDescriptor) Form_pg_attribute currentColumn = TupleDescAttr(tupleDescriptor, columnIndex); char *columnName = NameStr(currentColumn->attname); - if (currentColumn->attisdropped) + if (currentColumn->attisdropped +#if PG_VERSION_NUM >= 120000 + || currentColumn->attgenerated == ATTRIBUTE_GENERATED_STORED +#endif + ) { continue; } diff --git a/src/backend/distributed/commands/multi_copy.c b/src/backend/distributed/commands/multi_copy.c index defc08756..c62a10af3 100644 --- a/src/backend/distributed/commands/multi_copy.c +++ b/src/backend/distributed/commands/multi_copy.c @@ -64,6 +64,7 @@ #include "access/sysattr.h" #include "access/xact.h" #include "catalog/namespace.h" +#include "catalog/pg_attribute.h" #include "catalog/pg_type.h" #include "commands/copy.h" #include "commands/defrem.h" @@ -481,7 +482,11 @@ CopyToExistingShards(CopyStmt *copyStatement, char *completionTag) Form_pg_attribute currentColumn = TupleDescAttr(tupleDescriptor, columnIndex); char *columnName = NameStr(currentColumn->attname); - if (currentColumn->attisdropped) + if (currentColumn->attisdropped +#if PG_VERSION_NUM >= 120000 + || currentColumn->attgenerated == ATTRIBUTE_GENERATED_STORED +#endif + ) { continue; } @@ -510,7 +515,7 @@ CopyToExistingShards(CopyStmt *copyStatement, char *completionTag) * of BeginCopyFrom. However, we obviously should not do this in relcache * and therefore make a copy of the Relation. */ - copiedDistributedRelation = (Relation) palloc0(sizeof(RelationData)); + copiedDistributedRelation = (Relation) palloc(sizeof(RelationData)); copiedDistributedRelationTuple = (Form_pg_class) palloc(CLASS_TUPLE_SIZE); /* @@ -1028,7 +1033,11 @@ CanUseBinaryCopyFormat(TupleDesc tupleDescription) Form_pg_attribute currentColumn = TupleDescAttr(tupleDescription, columnIndex); Oid typeId = InvalidOid; - if (currentColumn->attisdropped) + if (currentColumn->attisdropped +#if PG_VERSION_NUM >= 120000 + || currentColumn->attgenerated == ATTRIBUTE_GENERATED_STORED +#endif + ) { continue; } @@ -1667,7 +1676,11 @@ AppendCopyRowData(Datum *valueArray, bool *isNullArray, TupleDesc rowDescriptor, value = CoerceColumnValue(value, &columnCoercionPaths[columnIndex]); } - if (currentColumn->attisdropped) + if (currentColumn->attisdropped +#if PG_VERSION_NUM >= 120000 + || currentColumn->attgenerated == ATTRIBUTE_GENERATED_STORED +#endif + ) { continue; } @@ -1787,7 +1800,11 @@ AvailableColumnCount(TupleDesc tupleDescriptor) { Form_pg_attribute currentColumn = TupleDescAttr(tupleDescriptor, columnIndex); - if (!currentColumn->attisdropped) + if (!currentColumn->attisdropped +#if PG_VERSION_NUM >= 120000 + && currentColumn->attgenerated != ATTRIBUTE_GENERATED_STORED +#endif + ) { columnCount++; } diff --git a/src/backend/distributed/utils/citus_ruleutils.c b/src/backend/distributed/utils/citus_ruleutils.c index d4c3cdfe1..f54c6f057 100644 --- a/src/backend/distributed/utils/citus_ruleutils.c +++ b/src/backend/distributed/utils/citus_ruleutils.c @@ -312,7 +312,7 @@ pg_get_tableschemadef_string(Oid tableRelationId, bool includeSequenceDefaults) * reasoning behind this is that Citus implements declarative partitioning * by creating the partitions first and then sending * "ALTER TABLE parent_table ATTACH PARTITION .." command. This may not play - * well with regular inhereted tables, which isn't a big concern from Citus' + * well with regular inherited tables, which isn't a big concern from Citus' * perspective. */ if (!attributeForm->attisdropped) @@ -371,7 +371,19 @@ pg_get_tableschemadef_string(Oid tableRelationId, bool includeSequenceDefaults) defaultString = deparse_expression(defaultNode, defaultContext, false, false); +#if PG_VERSION_NUM >= 120000 + if (attributeForm->attgenerated == ATTRIBUTE_GENERATED_STORED) + { + appendStringInfo(&buffer, " GENERATED ALWAYS AS (%s) STORED", + defaultString); + } + else + { + appendStringInfo(&buffer, " DEFAULT %s", defaultString); + } +#else appendStringInfo(&buffer, " DEFAULT %s", defaultString); +#endif } }