compareInVsAnyValues compares the values in IN syntax vs ANY syntax
(inExpr, anyExpr string)
| 1205 | |
| 1206 | // compareInVsAnyValues compares the values in IN syntax vs ANY syntax |
| 1207 | func compareInVsAnyValues(inExpr, anyExpr string) bool { |
| 1208 | // Extract values from IN expression: "column IN('A', 'B')" |
| 1209 | inValues := extractInValues(inExpr) |
| 1210 | if inValues == nil { |
| 1211 | return false |
| 1212 | } |
| 1213 | |
| 1214 | // Extract values from ANY expression: "(column = ANY (ARRAY['A'::text, 'B'::text]))" |
| 1215 | anyValues := extractAnyValues(anyExpr) |
| 1216 | if anyValues == nil { |
| 1217 | return false |
| 1218 | } |
| 1219 | |
| 1220 | // Compare the value sets |
| 1221 | if len(inValues) != len(anyValues) { |
| 1222 | return false |
| 1223 | } |
| 1224 | |
| 1225 | // Convert both to maps for comparison (order doesn't matter) |
| 1226 | inMap := make(map[string]bool) |
| 1227 | for _, v := range inValues { |
| 1228 | inMap[v] = true |
| 1229 | } |
| 1230 | |
| 1231 | anyMap := make(map[string]bool) |
| 1232 | for _, v := range anyValues { |
| 1233 | anyMap[v] = true |
| 1234 | } |
| 1235 | |
| 1236 | // Check if they contain the same values |
| 1237 | for v := range inMap { |
| 1238 | if !anyMap[v] { |
| 1239 | return false |
| 1240 | } |
| 1241 | } |
| 1242 | |
| 1243 | return true |
| 1244 | } |
| 1245 | |
| 1246 | // extractInValues extracts values from "column IN('A', 'B')" format |
| 1247 | func extractInValues(expr string) []string { |
no test coverage detected