Skip to content

Fix exact filters for numeric computed view columns#2717

Open
Ethan-kkk wants to merge 1 commit into
simonw:mainfrom
Ethan-kkk:fix-view-computed-column-filter
Open

Fix exact filters for numeric computed view columns#2717
Ethan-kkk wants to merge 1 commit into
simonw:mainfrom
Ethan-kkk:fix-view-computed-column-filter

Conversation

@Ethan-kkk
Copy link
Copy Markdown

Fixes #2713

This fixes filtering SQLite views by numeric computed columns, such as SUM(...) AS valid_count, where valid_count__exact=0 returned no rows even when the view contained rows with valid_count = 0.

URL query parameters are bound as strings, so valid_count__exact=0 binds "0" as text. Regular INTEGER table columns can rely on SQLite affinity for comparison, but computed view columns may have no declared type, so comparing integer 0 to text "0" does not match.

This change passes column details into filter SQL generation. For exact and not filters on columns with no declared type, numeric-looking filter values now include an additional guarded numeric comparison using typeof(column) in ('integer', 'real') and CAST(:p AS NUMERIC).

The original text comparison is preserved, so text values such as "00" are not incorrectly matched as numeric 0.

Tests cover:

  • valid_count__exact=0 on a computed numeric view column
  • valid_count__not=0 on the same view
  • preserving exact text matching for a computed text view column

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Filtering views on computed SUM columns returns 0 rows

1 participant