checkConstraintsEqual checks if two check constraints are equal.
(engine storepb.Engine, check1, check2 *storepb.CheckConstraintMetadata)
| 1148 | |
| 1149 | // checkConstraintsEqual checks if two check constraints are equal. |
| 1150 | func checkConstraintsEqual(engine storepb.Engine, check1, check2 *storepb.CheckConstraintMetadata) bool { |
| 1151 | // First try semantic comparison |
| 1152 | if CompareExpressionsSemantically(engine, check1.Expression, check2.Expression) { |
| 1153 | return true |
| 1154 | } |
| 1155 | |
| 1156 | // Handle PostgreSQL-specific normalizations |
| 1157 | // PostgreSQL converts "column IN (values)" to "column = ANY (ARRAY[values])" |
| 1158 | if isPostgreSQLInAnyEquivalent(check1.Expression, check2.Expression) || |
| 1159 | isPostgreSQLInAnyEquivalent(check2.Expression, check1.Expression) { |
| 1160 | return true |
| 1161 | } |
| 1162 | |
| 1163 | // Handle PostgreSQL interval syntax differences |
| 1164 | // Sync: (order_date >= (CURRENT_DATE - '1 year'::interval)) |
| 1165 | // Parser: order_date >= CURRENT_DATE - INTERVAL '1 year' |
| 1166 | if normalizePostgreSQLCheckConstraint(check1.Expression) == normalizePostgreSQLCheckConstraint(check2.Expression) { |
| 1167 | return true |
| 1168 | } |
| 1169 | |
| 1170 | return false |
| 1171 | } |
| 1172 | |
| 1173 | // isPostgreSQLInAnyEquivalent checks if expr1 contains IN syntax that PostgreSQL would normalize to ANY syntax in expr2 |
| 1174 | func isPostgreSQLInAnyEquivalent(expr1, expr2 string) bool { |
no test coverage detected