Skip to content

Commit 0310001

Browse files
store: Add guard for nocase ops on non-String columns
Signed-off-by: Maksim Dimitrov <dimitrov.maksim@gmail.com>
1 parent 69f4ebc commit 0310001

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

store/postgres/src/relational_queries.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,6 +1440,24 @@ impl<'a> Filter<'a> {
14401440
value: &'s Value,
14411441
) -> Result<Filter<'s>, StoreError> {
14421442
let column = table.column_for_field(attr)?;
1443+
1444+
// Case-insensitive operations only make sense for String columns.
1445+
// Other types (Bytes, BigInt, Int, etc.) don't have a concept of
1446+
// case and would fail at the SQL level (e.g. `bytea ~~* bytea`).
1447+
if matches!(op, ContainsOp::ILike | ContainsOp::NotILike)
1448+
&& !matches!(column.column_type(), ColumnType::String)
1449+
{
1450+
let filter = if op.negated() {
1451+
"not_contains_nocase"
1452+
} else {
1453+
"contains_nocase"
1454+
};
1455+
return Err(StoreError::UnsupportedFilter(
1456+
filter.to_owned(),
1457+
value.to_string(),
1458+
));
1459+
}
1460+
14431461
let pattern = QueryValue::new(value, column.column_type())?;
14441462
let pattern = match &pattern.value {
14451463
SqlValue::String(s) => {

0 commit comments

Comments
 (0)