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

Function isPostgreSQLInAnyEquivalent

backend/plugin/schema/differ.go:1174–1204  ·  view source on GitHub ↗

isPostgreSQLInAnyEquivalent checks if expr1 contains IN syntax that PostgreSQL would normalize to ANY syntax in expr2

(expr1, expr2 string)

Source from the content-addressed store, hash-verified

1172
1173// isPostgreSQLInAnyEquivalent checks if expr1 contains IN syntax that PostgreSQL would normalize to ANY syntax in expr2
1174func isPostgreSQLInAnyEquivalent(expr1, expr2 string) bool {
1175 // Clean up expressions for comparison
1176 expr1 = strings.TrimSpace(expr1)
1177 expr2 = strings.TrimSpace(expr2)
1178
1179 // Handle common PostgreSQL transformations:
1180 // "column IN ('A', 'B')" -> "(column = ANY (ARRAY['A'::text, 'B'::text]))"
1181
1182 // Very basic pattern matching for this specific case
1183 // Look for patterns like "column IN(...)" in expr1 and "column = ANY (ARRAY[...])" in expr2
1184 if strings.Contains(expr1, " IN(") || strings.Contains(expr1, " IN (") {
1185 // Extract the column name and values from IN expression
1186 if strings.Contains(expr2, " = ANY (ARRAY[") && strings.Contains(expr2, "::text") {
1187 // This is a simplified check - for a production system, you'd want more robust parsing
1188 // For now, just check if both expressions contain the same column name
1189 inParts := strings.Split(expr1, " IN")
1190 if len(inParts) >= 2 {
1191 column1 := strings.TrimSpace(inParts[0])
1192 // Remove any leading parentheses from column name
1193 column1 = strings.TrimPrefix(column1, "(")
1194
1195 if strings.HasPrefix(expr2, "("+column1+" = ANY") || strings.HasPrefix(expr2, column1+" = ANY") {
1196 // Extract values from both expressions and compare
1197 return compareInVsAnyValues(expr1, expr2)
1198 }
1199 }
1200 }
1201 }
1202
1203 return false
1204}
1205
1206// compareInVsAnyValues compares the values in IN syntax vs ANY syntax
1207func compareInVsAnyValues(inExpr, anyExpr string) bool {

Callers 1

checkConstraintsEqualFunction · 0.85

Calls 1

compareInVsAnyValuesFunction · 0.85

Tested by

no test coverage detected