Skip to content

Commit 2c20ba1

Browse files
committed
Tweak find_composite_type_dependencies API a bit more.
Per discussion with Noah Misch, the previous coding, introduced by my commit 65377e0 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.
1 parent 61cf7bc commit 2c20ba1

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

src/backend/commands/tablecmds.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3422,8 +3422,7 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
34223422
*/
34233423
if (newrel)
34243424
find_composite_type_dependencies(oldrel->rd_rel->reltype,
3425-
oldrel->rd_rel->relkind,
3426-
RelationGetRelationName(oldrel));
3425+
oldrel, NULL);
34273426

34283427
/*
34293428
* Generate the constraint and default execution states
@@ -3891,8 +3890,8 @@ ATTypedTableRecursion(List **wqueue, Relation rel, AlterTableCmd *cmd,
38913890
* to reject the ALTER. (How safe is this really?)
38923891
*/
38933892
void
3894-
find_composite_type_dependencies(Oid typeOid, char origRelkind,
3895-
const char *origRelname)
3893+
find_composite_type_dependencies(Oid typeOid, Relation origRelation,
3894+
const char *origTypeName)
38963895
{
38973896
Relation depRel;
38983897
ScanKeyData key[2];
@@ -3936,16 +3935,20 @@ find_composite_type_dependencies(Oid typeOid, char origRelkind,
39363935
if (rel->rd_rel->relkind == RELKIND_RELATION)
39373936
{
39383937
const char *msg;
3939-
if (origRelkind == RELKIND_COMPOSITE_TYPE)
3938+
3939+
if (origTypeName
3940+
|| origRelation->rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
39403941
msg = gettext_noop("cannot alter type \"%s\" because column \"%s\".\"%s\" uses it");
3941-
else if (origRelkind == RELKIND_FOREIGN_TABLE)
3942+
else if (origRelation->rd_rel->relkind == RELKIND_FOREIGN_TABLE)
39423943
msg = gettext_noop("cannot alter foreign table \"%s\" because column \"%s\".\"%s\" uses its rowtype");
39433944
else
39443945
msg = gettext_noop("cannot alter table \"%s\" because column \"%s\".\"%s\" uses its rowtype");
3946+
39453947
ereport(ERROR,
39463948
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
39473949
errmsg(msg,
3948-
origRelname,
3950+
origTypeName ? origTypeName
3951+
: RelationGetRelationName(origRelation),
39493952
RelationGetRelationName(rel),
39503953
NameStr(att->attname))));
39513954
}
@@ -3956,7 +3959,7 @@ find_composite_type_dependencies(Oid typeOid, char origRelkind,
39563959
* recursively check for indirect dependencies via its rowtype.
39573960
*/
39583961
find_composite_type_dependencies(rel->rd_rel->reltype,
3959-
origRelkind, origRelname);
3962+
origRelation, origTypeName);
39603963
}
39613964

39623965
relation_close(rel, AccessShareLock);
@@ -3972,7 +3975,7 @@ find_composite_type_dependencies(Oid typeOid, char origRelkind,
39723975
*/
39733976
arrayOid = get_array_type(typeOid);
39743977
if (OidIsValid(arrayOid))
3975-
find_composite_type_dependencies(arrayOid, origRelkind, origRelname);
3978+
find_composite_type_dependencies(arrayOid, origRelation, origTypeName);
39763979
}
39773980

39783981

@@ -6573,9 +6576,7 @@ ATPrepAlterColumnType(List **wqueue,
65736576
* For composite types, do this check now. Tables will check
65746577
* it later when the table is being rewritten.
65756578
*/
6576-
find_composite_type_dependencies(rel->rd_rel->reltype,
6577-
rel->rd_rel->relkind,
6578-
RelationGetRelationName(rel));
6579+
find_composite_type_dependencies(rel->rd_rel->reltype, rel, NULL);
65796580
}
65806581

65816582
ReleaseSysCache(tuple);

src/backend/commands/typecmds.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2196,7 +2196,7 @@ get_rels_with_domain(Oid domainOid, LOCKMODE lockmode)
21962196
*/
21972197
if (OidIsValid(rel->rd_rel->reltype))
21982198
find_composite_type_dependencies(rel->rd_rel->reltype,
2199-
RELKIND_COMPOSITE_TYPE,
2199+
NULL,
22002200
format_type_be(domainOid));
22012201

22022202
/* Otherwise we can ignore views, composite types, etc */

src/include/commands/tablecmds.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ extern void RenameRelationInternal(Oid myrelid,
5353
Oid namespaceId);
5454

5555
extern void find_composite_type_dependencies(Oid typeOid,
56-
char origRelkind, const char *origRelname);
56+
Relation origRelation,
57+
const char *origTypeName);
5758

5859
extern AttrNumber *varattnos_map(TupleDesc olddesc, TupleDesc newdesc);
5960
extern AttrNumber *varattnos_map_schema(TupleDesc old, List *schema);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy