(oldType, newType string)
| 1232 | } |
| 1233 | |
| 1234 | func 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 | |
| 1262 | func extractBaseType(typeName string) string { |
| 1263 | if idx := strings.Index(typeName, "("); idx >= 0 { |
no test coverage detected