MCPcopy Create free account
hub / github.com/bytebase/bytebase / requiresExplicitCasting

Function requiresExplicitCasting

backend/plugin/schema/pg/metadata_migration.go:1234–1260  ·  view source on GitHub ↗
(oldType, newType string)

Source from the content-addressed store, hash-verified

1232}
1233
1234func requiresExplicitCasting(oldType, newType string) bool {
1235 oldBaseType := extractBaseType(oldType)
1236 newBaseType := extractBaseType(newType)
1237 if oldBaseType == newBaseType {
1238 return requiresUsingForSameType(oldType, newType)
1239 }
1240 incompatibleConversions := map[string][]string{
1241 "text": {"integer", "numeric", "real", pgTypeDoublePrecision, "smallint", "bigint", "boolean"},
1242 pgTypeCharacterVarying: {"integer", "numeric", "real", pgTypeDoublePrecision, "smallint", "bigint", "boolean"},
1243 "character": {"integer", "numeric", "real", pgTypeDoublePrecision, "smallint", "bigint", "boolean"},
1244 "jsonb": {"text", pgTypeCharacterVarying, "character"},
1245 "json": {"text", pgTypeCharacterVarying, "character"},
1246 "integer[]": {"text", pgTypeCharacterVarying, "character"},
1247 "text[]": {"text", pgTypeCharacterVarying, "character"},
1248 "bigint": {"smallint", "integer"},
1249 pgTypeDoublePrecision: {"real"},
1250 "timestamp with time zone": {"date"},
1251 "timestamp without time zone": {"date"},
1252 "numeric": {"integer", "smallint", "bigint", "real", pgTypeDoublePrecision},
1253 }
1254 for _, target := range incompatibleConversions[oldBaseType] {
1255 if target == newBaseType {
1256 return true
1257 }
1258 }
1259 return false
1260}
1261
1262func extractBaseType(typeName string) string {
1263 if idx := strings.Index(typeName, "("); idx >= 0 {

Callers 1

writeAlterColumnDiffFunction · 0.85

Calls 2

extractBaseTypeFunction · 0.85
requiresUsingForSameTypeFunction · 0.85

Tested by

no test coverage detected