mirror of
https://github.com/postgres/postgres.git
synced 2025-07-03 20:02:46 +03:00
Reject change of output-column collation in CREATE OR REPLACE VIEW.
checkViewTupleDesc() didn't get the memo that it should verify same attcollation along with same type/typmod. (A quick scan did not find other similar oversights.) Per bug #17404 from Pierre-Aurélien Georges. On another day I might've back-patched this, but today I'm feeling paranoid about unnecessary behavioral changes in back branches. Discussion: https://postgr.es/m/17404-8a4a270ef30a6709@postgresql.org
This commit is contained in:
@ -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))));
|
||||
}
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user