aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/view.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/commands/view.c')
-rw-r--r--src/backend/commands/view.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/backend/commands/view.c b/src/backend/commands/view.c
index e183ab097c4..459e9821d08 100644
--- a/src/backend/commands/view.c
+++ b/src/backend/commands/view.c
@@ -282,7 +282,12 @@ checkViewTupleDesc(TupleDesc newdesc, TupleDesc olddesc)
NameStr(oldattr->attname),
NameStr(newattr->attname)),
errhint("Use ALTER VIEW ... RENAME COLUMN ... to change name of view column instead.")));
- /* XXX would it be safe to allow atttypmod to change? Not sure */
+
+ /*
+ * We cannot allow type, typmod, or collation to change, since these
+ * properties may be embedded in Vars of other views/rules referencing
+ * this one. Other column attributes can be ignored.
+ */
if (newattr->atttypid != oldattr->atttypid ||
newattr->atttypmod != oldattr->atttypmod)
ereport(ERROR,
@@ -293,7 +298,18 @@ checkViewTupleDesc(TupleDesc newdesc, TupleDesc olddesc)
oldattr->atttypmod),
format_type_with_typemod(newattr->atttypid,
newattr->atttypmod))));
- /* We can ignore the remaining attributes of an attribute... */
+
+ /*
+ * At this point, attcollations should be both valid or both invalid,
+ * so applying get_collation_name unconditionally should be fine.
+ */
+ if (newattr->attcollation != oldattr->attcollation)
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_TABLE_DEFINITION),
+ errmsg("cannot change collation of view column \"%s\" from \"%s\" to \"%s\"",
+ NameStr(oldattr->attname),
+ get_collation_name(oldattr->attcollation),
+ get_collation_name(newattr->attcollation))));
}
/*