diff --git a/store/postgres/src/relational_queries.rs b/store/postgres/src/relational_queries.rs index aa439e4c1c3..89efd0415da 100644 --- a/store/postgres/src/relational_queries.rs +++ b/store/postgres/src/relational_queries.rs @@ -1618,17 +1618,31 @@ impl<'a> Filter<'a> { out.push_sql(") > 0"); } } - SqlValue::List(_) | SqlValue::Numerics(_) => { - if op.negated() { - out.push_sql(" not "); - column.walk_ast(out.reborrow())?; - out.push_sql(" && "); - } else { + SqlValue::List(_) | SqlValue::Numerics(_) => match op { + // For case-insensitive operations + ContainsOp::ILike | ContainsOp::NotILike => { + if op.negated() { + out.push_sql(" not "); + } + out.push_sql("exists (select 1 from unnest("); column.walk_ast(out.reborrow())?; - out.push_sql(" @> "); + out.push_sql(") as elem where elem ilike any("); + qv.walk_ast(out.reborrow())?; + out.push_sql("))"); } - qv.walk_ast(out)?; - } + _ => { + // For case-sensitive operations + if op.negated() { + out.push_sql(" not "); + column.walk_ast(out.reborrow())?; + out.push_sql(" && "); + } else { + column.walk_ast(out.reborrow())?; + out.push_sql(" @> "); + } + qv.walk_ast(out)?; + } + }, SqlValue::Null | SqlValue::Bool(_) | SqlValue::Numeric(_) diff --git a/store/test-store/tests/graphql/query.rs b/store/test-store/tests/graphql/query.rs index 0c219558e14..5acf9754772 100644 --- a/store/test-store/tests/graphql/query.rs +++ b/store/test-store/tests/graphql/query.rs @@ -2880,6 +2880,31 @@ fn can_query_with_or_explicit_and_filter() { }) } +#[test] +fn can_query_array_contains_nocase() { + const QUERY: &str = " + query { + musicians(where: { bands_contains_nocase: [\"B1\", \"B2\"] }) { + name + bands { id } + } + } + "; + + run_query(QUERY, |result, _| { + let exp = object! { + musicians: vec![ + object! { name: "John", bands: vec![object! { id: "b1" }, object! { id: "b2" }] }, + object! { name: "Lisa", bands: vec![object! { id: "b1" }] }, + object! { name: "Tom", bands: vec![object! { id: "b1" }, object! { id: "b2" }] }, + object! { name: "Paul", bands: vec![ object! { id: "b2" }] }, + ], + }; + let data = extract_data!(result).unwrap(); + assert_eq!(data, exp); + }) +} + #[test] fn can_query_with_or_implicit_and_filter() { const QUERY: &str = "