>From 648f702b90ae05564e2792277ce279047f53566c Mon Sep 17 00:00:00 2001
From: Kyotaro Horiguchi <horiguchi.kyotaro@lab.ntt.co.jp>
Date: Mon, 16 Feb 2015 20:05:43 +0900
Subject: [PATCH 3/4] Check new reg* types are not used as default values

The new OID alias types don't behave as the same as the other OID
alias types concerning object dependency. To get rid of confusion,
inhibit constants of these types from appearing where dependencies are
registered for other types.
---
 src/backend/catalog/dependency.c | 23 +++++++++++++++++++++++
 src/backend/catalog/heap.c       |  1 +
 2 files changed, 24 insertions(+)

diff --git a/src/backend/catalog/dependency.c b/src/backend/catalog/dependency.c
index bacb242..a59c2cd 100644
--- a/src/backend/catalog/dependency.c
+++ b/src/backend/catalog/dependency.c
@@ -1597,6 +1597,29 @@ find_expr_references_walker(Node *node,
 						add_object_address(OCLASS_TSDICT, objoid, 0,
 										   context->addrs);
 					break;
+
+				/*
+				 * Dependencies for regrole and regnamespace in expressions
+				 * are not handled as same as other reg* types. So explicitly
+				 * inhibit the usage to get rid of confusions.
+				 */
+				case REGROLEOID:
+				case REGNAMESPACEOID:
+				{
+					HeapTuple tt;
+					char *typename = "<unknown>";
+
+					tt = SearchSysCache1(TYPEOID, con->consttype);
+					if (HeapTupleIsValid(tt))
+						typename = pstrdup(NameStr(((Form_pg_type)
+													GETSTRUCT(tt))->typname));
+					ReleaseSysCache(tt);
+					ereport(ERROR,
+							(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+							 errmsg("constant of the type \'%s\' cannot be used here",
+									typename)));
+				}
+				break;
 			}
 		}
 		return false;
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c
index 17f7266..fa5957a 100644
--- a/src/backend/catalog/heap.c
+++ b/src/backend/catalog/heap.c
@@ -1860,6 +1860,7 @@ StoreAttrDefault(Relation rel, AttrNumber attnum,
 	Oid			attrdefOid;
 	ObjectAddress colobject,
 				defobject;
+	Oid			exprtype;
 
 	/*
 	 * Flatten expression to string form for storage.
-- 
2.1.0.GIT

