Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/clickhouse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function mapFilter(column: string, operator: string, name: string, type: string
case OPERATORS.equals:
return `${column} = ${value}`;
case OPERATORS.notEquals:
return `${column} != ${value}`;
return `(${column} != ${value} OR ${column} = '')`;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Tautology when filtering by empty string

The guard OR ${column} = '' is the ClickHouse equivalent of IS NULL for Postgres, but it introduces a tautology when the filter value itself is an empty string ''. In that case the generated SQL becomes:

(column != '' OR column = '')

which is always TRUE for every row — so a "not equals empty-string" filter would return the entire dataset instead of excluding nothing. In practice users are unlikely to filter on an exact empty-string value, but it is worth being aware of this edge case. The Prisma fix avoids this because IS NULL only catches NULL, not the '' value itself.

case OPERATORS.contains:
return `positionCaseInsensitive(${column}, ${value}) > 0`;
case OPERATORS.doesNotContain:
Expand Down
4 changes: 2 additions & 2 deletions src/lib/prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ function mapFilter(column: string, operator: string, name: string, type: string
case OPERATORS.equals:
return `${column} = ${value}`;
case OPERATORS.notEquals:
return `${column} != ${value}`;
return `(${column} != ${value} OR ${column} IS NULL)`;
case OPERATORS.contains:
return `${column} ilike ${value}`;
case OPERATORS.doesNotContain:
return `${column} not ilike ${value}`;
return `(${column} not ilike ${value} OR ${column} IS NULL)`;
default:
return '';
}
Expand Down