mirror of
https://github.com/postgres/postgres.git
synced 2025-04-27 22:56:53 +03:00
Tweak find_composite_type_dependencies API a bit more.
Per discussion with Noah Misch, the previous coding, introduced by my commit 65377e0b9c0e0397b1598b38b6a7fb8b6f740d39 on 2011-02-06, was really an abuse of RELKIND_COMPOSITE_TYPE, since the caller in typecmds.c is actually passing the name of a domain. So go back having a type name argument, but make the first argument a Relation rather than just a string so we can tell whether it's a table or a foreign table and emit the proper error message.
This commit is contained in:
parent
61cf7bcdf7
commit
2c20ba1fd2
@ -3422,8 +3422,7 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
|
|||||||
*/
|
*/
|
||||||
if (newrel)
|
if (newrel)
|
||||||
find_composite_type_dependencies(oldrel->rd_rel->reltype,
|
find_composite_type_dependencies(oldrel->rd_rel->reltype,
|
||||||
oldrel->rd_rel->relkind,
|
oldrel, NULL);
|
||||||
RelationGetRelationName(oldrel));
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Generate the constraint and default execution states
|
* Generate the constraint and default execution states
|
||||||
@ -3891,8 +3890,8 @@ ATTypedTableRecursion(List **wqueue, Relation rel, AlterTableCmd *cmd,
|
|||||||
* to reject the ALTER. (How safe is this really?)
|
* to reject the ALTER. (How safe is this really?)
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
find_composite_type_dependencies(Oid typeOid, char origRelkind,
|
find_composite_type_dependencies(Oid typeOid, Relation origRelation,
|
||||||
const char *origRelname)
|
const char *origTypeName)
|
||||||
{
|
{
|
||||||
Relation depRel;
|
Relation depRel;
|
||||||
ScanKeyData key[2];
|
ScanKeyData key[2];
|
||||||
@ -3936,16 +3935,20 @@ find_composite_type_dependencies(Oid typeOid, char origRelkind,
|
|||||||
if (rel->rd_rel->relkind == RELKIND_RELATION)
|
if (rel->rd_rel->relkind == RELKIND_RELATION)
|
||||||
{
|
{
|
||||||
const char *msg;
|
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");
|
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");
|
msg = gettext_noop("cannot alter foreign table \"%s\" because column \"%s\".\"%s\" uses its rowtype");
|
||||||
else
|
else
|
||||||
msg = gettext_noop("cannot alter table \"%s\" because column \"%s\".\"%s\" uses its rowtype");
|
msg = gettext_noop("cannot alter table \"%s\" because column \"%s\".\"%s\" uses its rowtype");
|
||||||
|
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||||
errmsg(msg,
|
errmsg(msg,
|
||||||
origRelname,
|
origTypeName ? origTypeName
|
||||||
|
: RelationGetRelationName(origRelation),
|
||||||
RelationGetRelationName(rel),
|
RelationGetRelationName(rel),
|
||||||
NameStr(att->attname))));
|
NameStr(att->attname))));
|
||||||
}
|
}
|
||||||
@ -3956,7 +3959,7 @@ find_composite_type_dependencies(Oid typeOid, char origRelkind,
|
|||||||
* recursively check for indirect dependencies via its rowtype.
|
* recursively check for indirect dependencies via its rowtype.
|
||||||
*/
|
*/
|
||||||
find_composite_type_dependencies(rel->rd_rel->reltype,
|
find_composite_type_dependencies(rel->rd_rel->reltype,
|
||||||
origRelkind, origRelname);
|
origRelation, origTypeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
relation_close(rel, AccessShareLock);
|
relation_close(rel, AccessShareLock);
|
||||||
@ -3972,7 +3975,7 @@ find_composite_type_dependencies(Oid typeOid, char origRelkind,
|
|||||||
*/
|
*/
|
||||||
arrayOid = get_array_type(typeOid);
|
arrayOid = get_array_type(typeOid);
|
||||||
if (OidIsValid(arrayOid))
|
if (OidIsValid(arrayOid))
|
||||||
find_composite_type_dependencies(arrayOid, origRelkind, origRelname);
|
find_composite_type_dependencies(arrayOid, origRelation, origTypeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -6573,9 +6576,7 @@ ATPrepAlterColumnType(List **wqueue,
|
|||||||
* For composite types, do this check now. Tables will check
|
* For composite types, do this check now. Tables will check
|
||||||
* it later when the table is being rewritten.
|
* it later when the table is being rewritten.
|
||||||
*/
|
*/
|
||||||
find_composite_type_dependencies(rel->rd_rel->reltype,
|
find_composite_type_dependencies(rel->rd_rel->reltype, rel, NULL);
|
||||||
rel->rd_rel->relkind,
|
|
||||||
RelationGetRelationName(rel));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ReleaseSysCache(tuple);
|
ReleaseSysCache(tuple);
|
||||||
|
@ -2196,7 +2196,7 @@ get_rels_with_domain(Oid domainOid, LOCKMODE lockmode)
|
|||||||
*/
|
*/
|
||||||
if (OidIsValid(rel->rd_rel->reltype))
|
if (OidIsValid(rel->rd_rel->reltype))
|
||||||
find_composite_type_dependencies(rel->rd_rel->reltype,
|
find_composite_type_dependencies(rel->rd_rel->reltype,
|
||||||
RELKIND_COMPOSITE_TYPE,
|
NULL,
|
||||||
format_type_be(domainOid));
|
format_type_be(domainOid));
|
||||||
|
|
||||||
/* Otherwise we can ignore views, composite types, etc */
|
/* Otherwise we can ignore views, composite types, etc */
|
||||||
|
@ -53,7 +53,8 @@ extern void RenameRelationInternal(Oid myrelid,
|
|||||||
Oid namespaceId);
|
Oid namespaceId);
|
||||||
|
|
||||||
extern void find_composite_type_dependencies(Oid typeOid,
|
extern void find_composite_type_dependencies(Oid typeOid,
|
||||||
char origRelkind, const char *origRelname);
|
Relation origRelation,
|
||||||
|
const char *origTypeName);
|
||||||
|
|
||||||
extern AttrNumber *varattnos_map(TupleDesc olddesc, TupleDesc newdesc);
|
extern AttrNumber *varattnos_map(TupleDesc olddesc, TupleDesc newdesc);
|
||||||
extern AttrNumber *varattnos_map_schema(TupleDesc old, List *schema);
|
extern AttrNumber *varattnos_map_schema(TupleDesc old, List *schema);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user