Skip to content

Commit 20c1a0f

Browse files
elianddbclaude
andcommitted
Use utility functions for string type checking
Replace manual type checks with types.IsTextOnly() and types.IsBinaryType() for cleaner, more maintainable code. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 25c8d4a commit 20c1a0f

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

sql/plan/alter_foreign_key.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -669,10 +669,9 @@ func foreignKeyComparableTypes(ctx *sql.Context, type1 sql.Type, type2 sql.Type)
669669
}
670670

671671
// Handle string types (both same-type with different lengths and mixed types)
672-
if ((t1 == sqltypes.Char || t1 == sqltypes.VarChar) && (t2 == sqltypes.Char || t2 == sqltypes.VarChar)) ||
673-
((t1 == sqltypes.Binary || t1 == sqltypes.VarBinary) && (t2 == sqltypes.Binary || t2 == sqltypes.VarBinary)) {
674-
// There seems to be a special case where CHAR/VARCHAR/BINARY/VARBINARY can have unequal lengths.
675-
// Have not tested every type nor combination, but this seems specific to those 4 types.
672+
if (types.IsTextOnly(type1) && types.IsTextOnly(type2)) ||
673+
(types.IsBinaryType(type1) && types.IsBinaryType(type2)) {
674+
// String types must have matching character sets
676675
type1String := type1.(sql.StringType)
677676
type2String := type2.(sql.StringType)
678677
return type1String.Collation().CharacterSet() == type2String.Collation().CharacterSet()

0 commit comments

Comments
 (0)