From 57b9dcc53457f5afcfab023b591f95865c1a5a90 Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.munro@enterprisedb.com>
Date: Wed, 29 Nov 2017 20:40:30 +1300
Subject: [PATCH] TupleDescCopy needs to clear atthasdef, attnotnull,
 attidentity.

Commit cc5f81366c36 introduced TupleDescCopy() to copy tuple descriptors into
caller supplied memory without defaults or contraints.  It failed to clear
the per-attribute flags indicating whether there are defaults or constraints,
as the similar function CreateTupleDescCopy() does.  Likewise, the identity
column flag should be cleared following the example of CreateTupleDescCopy().
Repair.

Author: Thomas Munro
Reported-By: Andrew Gierth
Discussion:
---
 src/backend/access/common/tupdesc.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/backend/access/common/tupdesc.c b/src/backend/access/common/tupdesc.c
index 9e37ca73a86..6eedefa803a 100644
--- a/src/backend/access/common/tupdesc.c
+++ b/src/backend/access/common/tupdesc.c
@@ -195,7 +195,17 @@ CreateTupleDescCopyConstr(TupleDesc tupdesc)
 void
 TupleDescCopy(TupleDesc dst, TupleDesc src)
 {
+	int			i;
+
 	memcpy(dst, src, TupleDescSize(src));
+	for (i = 0; i < dst->natts; ++i)
+	{
+		Form_pg_attribute att = TupleDescAttr(dst, i);
+
+		att->attnotnull = false;
+		att->atthasdef = false;
+		att->attidentity = '\0';
+	}
 	dst->constr = NULL;
 	dst->tdrefcount = -1;
 }
-- 
2.15.0

