Skip to content

Commit 49a642a

Browse files
committed
Add check for matching column collations in ALTER TABLE ... INHERIT.
The other DDL operations that create an inheritance relationship were checking for collation match already, but this one got missed. Also fix comments that failed to mention collation checks.
1 parent c947325 commit 49a642a

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/backend/commands/tablecmds.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,7 +1434,7 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
14341434

14351435
/*
14361436
* Yes, try to merge the two column definitions. They must
1437-
* have the same type and typmod.
1437+
* have the same type, typmod, and collation.
14381438
*/
14391439
ereport(NOTICE,
14401440
(errmsg("merging multiple inherited definitions of column \"%s\"",
@@ -1620,7 +1620,7 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
16201620

16211621
/*
16221622
* Yes, try to merge the two column definitions. They must
1623-
* have the same type and typmod.
1623+
* have the same type, typmod, and collation.
16241624
*/
16251625
ereport(NOTICE,
16261626
(errmsg("merging column \"%s\" with inherited definition",
@@ -4121,7 +4121,7 @@ ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel,
41214121
int32 ctypmod;
41224122
Oid ccollid;
41234123

4124-
/* Child column must match by type */
4124+
/* Child column must match on type, typmod, and collation */
41254125
typenameTypeIdAndMod(NULL, colDef->typeName, &ctypeId, &ctypmod);
41264126
if (ctypeId != childatt->atttypid ||
41274127
ctypmod != childatt->atttypmod)
@@ -8178,7 +8178,7 @@ MergeAttributesIntoExisting(Relation child_rel, Relation parent_rel)
81788178
attributeName);
81798179
if (HeapTupleIsValid(tuple))
81808180
{
8181-
/* Check they are same type and typmod */
8181+
/* Check they are same type, typmod, and collation */
81828182
Form_pg_attribute childatt = (Form_pg_attribute) GETSTRUCT(tuple);
81838183

81848184
if (attribute->atttypid != childatt->atttypid ||
@@ -8189,6 +8189,17 @@ MergeAttributesIntoExisting(Relation child_rel, Relation parent_rel)
81898189
RelationGetRelationName(child_rel),
81908190
attributeName)));
81918191

8192+
if (attribute->attcollation != childatt->attcollation)
8193+
ereport(ERROR,
8194+
(errcode(ERRCODE_COLLATION_MISMATCH),
8195+
errmsg("child table \"%s\" has different collation for column \"%s\"",
8196+
RelationGetRelationName(child_rel),
8197+
attributeName)));
8198+
8199+
/*
8200+
* Check child doesn't discard NOT NULL property. (Other
8201+
* constraints are checked elsewhere.)
8202+
*/
81928203
if (attribute->attnotnull && !childatt->attnotnull)
81938204
ereport(ERROR,
81948205
(errcode(ERRCODE_DATATYPE_MISMATCH),

0 commit comments

Comments
 (0)