fix: use AND instead of OR in neq filter for null-equivalent values (#19071)
Fixes #19070 The `neq` operator in `compute-where-condition-parts.ts` uses `OR` where it should use `AND` when handling null-equivalent values. Currently generates: ```sql field != '' OR field IS NOT NULL ``` For a row where `field = ''`: - `'' != ''` = false - `'' IS NOT NULL` = true - `false OR true` = true -- row incorrectly passes the filter The `eq` operator correctly uses `OR field IS NULL` because it's additive (match value or its null equivalent). By De Morgan's law, the negation `neq` needs `AND field IS NOT NULL` -- exclude if the value doesn't match AND is not a null equivalent. With the fix: ```sql field != '' AND field IS NOT NULL ``` - `'' != ''` = false, `'' IS NOT NULL` = true, `false AND true` = false -- correctly excluded - `NULL != ''` = NULL, `NULL IS NOT NULL` = false, `NULL AND false` = false -- correctly excluded - `'Alice' != ''` = true, `'Alice' IS NOT NULL` = true, `true AND true` = true -- correctly included Affects `neq` filters on TEXT fields and all composite sub-fields (firstName, lastName, primaryEmail, primaryPhoneNumber, address sub-fields, etc.) when filtering against null-equivalent values. Co-authored-by: Etienne <45695613+etiennejouan@users.noreply.github.com>
This commit is contained in:
+1
-1
@@ -65,7 +65,7 @@ export const computeWhereConditionParts = ({
|
||||
};
|
||||
case 'neq':
|
||||
return {
|
||||
sql: `${fieldReference} != :${key}${paramSuffix}${hasNullEquivalentFieldValue ? ` OR ${fieldReference} IS NOT NULL` : ''}`,
|
||||
sql: `${fieldReference} != :${key}${paramSuffix}${hasNullEquivalentFieldValue ? ` AND ${fieldReference} IS NOT NULL` : ''}`,
|
||||
params: { [`${key}${paramSuffix}`]: value },
|
||||
};
|
||||
case 'gt':
|
||||
|
||||
Reference in New Issue
Block a user