PG: Fix containedIn query on empty array (#5254)

* PG: Fix containedIn query on empty array

* improve logic
This commit is contained in:
Diamond Lewis
2018-12-19 17:57:55 -06:00
committed by GitHub
parent 631b1684e2
commit ab32dbc9a2
2 changed files with 32 additions and 1 deletions

View File

@@ -402,8 +402,8 @@ const buildWhereClause = ({ schema, query, index }): WhereClause => {
index = index + 1 + inPatterns.length;
} else if (isInOrNin) {
var createConstraint = (baseArray, notIn) => {
const not = notIn ? ' NOT ' : '';
if (baseArray.length > 0) {
const not = notIn ? ' NOT ' : '';
if (isArrayField) {
patterns.push(
`${not} array_contains($${index}:name, $${index + 1})`
@@ -430,6 +430,13 @@ const buildWhereClause = ({ schema, query, index }): WhereClause => {
values.push(fieldName);
patterns.push(`$${index}:name IS NULL`);
index = index + 1;
} else {
// Handle empty array
if (notIn) {
patterns.push('1 = 1'); // Return all values
} else {
patterns.push('1 = 2'); // Return no values
}
}
};
if (fieldValue.$in) {