diff options
author | Tom Lane | 2022-02-15 17:57:44 +0000 |
---|---|---|
committer | Tom Lane | 2022-02-15 17:57:44 +0000 |
commit | 2523928b285b06242e0c669fadfc76d73bafdd66 (patch) | |
tree | fb26df74cdc176c0d9f6bfe36e334679c5dbb9c5 /src/backend/commands/view.c | |
parent | 4d373e05286daff05d7fd0f6e4ab7ff4e5304d81 (diff) |
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
Diffstat (limited to 'src/backend/commands/view.c')
-rw-r--r-- | src/backend/commands/view.c | 20 |
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)))); } /* |