mirror of
https://github.com/postgres/postgres.git
synced 2025-06-30 21:42:05 +03:00
Fix my oversight in enabling domains-of-domains: ALTER DOMAIN ADD CONSTRAINT
needs to check the new constraint against columns of derived domains too. Also, make it error out if the domain to be modified is used within any composite-type columns. Eventually we should support that case, but it seems a bit painful, and not suitable for a back-patch. For the moment just let the user know we can't do it. Backpatch to 8.2, which is the only released version that allows nested domains. Possibly the other part should be back-patched further.
This commit is contained in:
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.220 2007/05/11 17:57:12 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.221 2007/05/11 20:16:36 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -206,8 +206,6 @@ static void ATSimpleRecursion(List **wqueue, Relation rel,
|
||||
AlterTableCmd *cmd, bool recurse);
|
||||
static void ATOneLevelRecursion(List **wqueue, Relation rel,
|
||||
AlterTableCmd *cmd);
|
||||
static void find_composite_type_dependencies(Oid typeOid,
|
||||
const char *origTblName);
|
||||
static void ATPrepAddColumn(List **wqueue, Relation rel, bool recurse,
|
||||
AlterTableCmd *cmd);
|
||||
static void ATExecAddColumn(AlteredTableInfo *tab, Relation rel,
|
||||
@ -2410,7 +2408,8 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap)
|
||||
*/
|
||||
if (newrel)
|
||||
find_composite_type_dependencies(oldrel->rd_rel->reltype,
|
||||
RelationGetRelationName(oldrel));
|
||||
RelationGetRelationName(oldrel),
|
||||
NULL);
|
||||
|
||||
/*
|
||||
* Generate the constraint and default execution states
|
||||
@ -2812,16 +2811,21 @@ ATOneLevelRecursion(List **wqueue, Relation rel,
|
||||
/*
|
||||
* find_composite_type_dependencies
|
||||
*
|
||||
* Check to see if a table's rowtype is being used as a column in some
|
||||
* Check to see if a composite type is being used as a column in some
|
||||
* other table (possibly nested several levels deep in composite types!).
|
||||
* Eventually, we'd like to propagate the check or rewrite operation
|
||||
* into other such tables, but for now, just error out if we find any.
|
||||
*
|
||||
* Caller should provide either a table name or a type name (not both) to
|
||||
* report in the error message, if any.
|
||||
*
|
||||
* We assume that functions and views depending on the type are not reasons
|
||||
* to reject the ALTER. (How safe is this really?)
|
||||
*/
|
||||
static void
|
||||
find_composite_type_dependencies(Oid typeOid, const char *origTblName)
|
||||
void
|
||||
find_composite_type_dependencies(Oid typeOid,
|
||||
const char *origTblName,
|
||||
const char *origTypeName)
|
||||
{
|
||||
Relation depRel;
|
||||
ScanKeyData key[2];
|
||||
@ -2864,12 +2868,20 @@ find_composite_type_dependencies(Oid typeOid, const char *origTblName)
|
||||
|
||||
if (rel->rd_rel->relkind == RELKIND_RELATION)
|
||||
{
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("cannot alter table \"%s\" because column \"%s\".\"%s\" uses its rowtype",
|
||||
origTblName,
|
||||
RelationGetRelationName(rel),
|
||||
NameStr(att->attname))));
|
||||
if (origTblName)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("cannot alter table \"%s\" because column \"%s\".\"%s\" uses its rowtype",
|
||||
origTblName,
|
||||
RelationGetRelationName(rel),
|
||||
NameStr(att->attname))));
|
||||
else
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("cannot alter type \"%s\" because column \"%s\".\"%s\" uses it",
|
||||
origTypeName,
|
||||
RelationGetRelationName(rel),
|
||||
NameStr(att->attname))));
|
||||
}
|
||||
else if (OidIsValid(rel->rd_rel->reltype))
|
||||
{
|
||||
@ -2878,7 +2890,7 @@ find_composite_type_dependencies(Oid typeOid, const char *origTblName)
|
||||
* recursively check for indirect dependencies via its rowtype.
|
||||
*/
|
||||
find_composite_type_dependencies(rel->rd_rel->reltype,
|
||||
origTblName);
|
||||
origTblName, origTypeName);
|
||||
}
|
||||
|
||||
relation_close(rel, AccessShareLock);
|
||||
@ -2894,7 +2906,7 @@ find_composite_type_dependencies(Oid typeOid, const char *origTblName)
|
||||
*/
|
||||
arrayOid = get_array_type(typeOid);
|
||||
if (OidIsValid(arrayOid))
|
||||
find_composite_type_dependencies(arrayOid, origTblName);
|
||||
find_composite_type_dependencies(arrayOid, origTblName, origTypeName);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user