*/
if (newrel)
find_composite_type_dependencies(oldrel->rd_rel->reltype,
- oldrel->rd_rel->relkind,
- RelationGetRelationName(oldrel));
+ oldrel, NULL);
/*
* Generate the constraint and default execution states
* to reject the ALTER. (How safe is this really?)
*/
void
-find_composite_type_dependencies(Oid typeOid, char origRelkind,
- const char *origRelname)
+find_composite_type_dependencies(Oid typeOid, Relation origRelation,
+ const char *origTypeName)
{
Relation depRel;
ScanKeyData key[2];
if (rel->rd_rel->relkind == RELKIND_RELATION)
{
const char *msg;
- if (origRelkind == RELKIND_COMPOSITE_TYPE)
+
+ if (origTypeName
+ || origRelation->rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
msg = gettext_noop("cannot alter type \"%s\" because column \"%s\".\"%s\" uses it");
- else if (origRelkind == RELKIND_FOREIGN_TABLE)
+ else if (origRelation->rd_rel->relkind == RELKIND_FOREIGN_TABLE)
msg = gettext_noop("cannot alter foreign table \"%s\" because column \"%s\".\"%s\" uses its rowtype");
else
msg = gettext_noop("cannot alter table \"%s\" because column \"%s\".\"%s\" uses its rowtype");
+
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg(msg,
- origRelname,
+ origTypeName ? origTypeName
+ : RelationGetRelationName(origRelation),
RelationGetRelationName(rel),
NameStr(att->attname))));
}
* recursively check for indirect dependencies via its rowtype.
*/
find_composite_type_dependencies(rel->rd_rel->reltype,
- origRelkind, origRelname);
+ origRelation, origTypeName);
}
relation_close(rel, AccessShareLock);
*/
arrayOid = get_array_type(typeOid);
if (OidIsValid(arrayOid))
- find_composite_type_dependencies(arrayOid, origRelkind, origRelname);
+ find_composite_type_dependencies(arrayOid, origRelation, origTypeName);
}
* For composite types, do this check now. Tables will check
* it later when the table is being rewritten.
*/
- find_composite_type_dependencies(rel->rd_rel->reltype,
- rel->rd_rel->relkind,
- RelationGetRelationName(rel));
+ find_composite_type_dependencies(rel->rd_rel->reltype, rel, NULL);
}
ReleaseSysCache(tuple);