diff --git a/datasette/filters.py b/datasette/filters.py index 2b859d9992..cbd9441555 100644 --- a/datasette/filters.py +++ b/datasette/filters.py @@ -149,19 +149,13 @@ class Filters: TemplatedFilter( "arraycontains", "array contains", - """rowid in ( - select {t}.rowid from {t}, json_each([{t}].[{c}]) j - where j.value = :{p} - )""", + """:{p} in (select value from json_each([{t}].[{c}]))""", '{c} contains "{v}"', ), TemplatedFilter( "arraynotcontains", "array does not contain", - """rowid not in ( - select {t}.rowid from {t}, json_each([{t}].[{c}]) j - where j.value = :{p} - )""", + """:{p} not in (select value from json_each([{t}].[{c}]))""", '{c} does not contain "{v}"', ), ] diff --git a/tests/test_filters.py b/tests/test_filters.py index f22b7b5cc6..d05ae80fae 100644 --- a/tests/test_filters.py +++ b/tests/test_filters.py @@ -56,12 +56,15 @@ # Not in, and JSON array not in ((("foo__notin", "1,2,3"),), ["foo not in (:p0, :p1, :p2)"], ["1", "2", "3"]), ((("foo__notin", "[1,2,3]"),), ["foo not in (:p0, :p1, :p2)"], [1, 2, 3]), - # JSON arraycontains + # JSON arraycontains, arraynotcontains ( (("Availability+Info__arraycontains", "yes"),), - [ - "rowid in (\n select table.rowid from table, json_each([table].[Availability+Info]) j\n where j.value = :p0\n )" - ], + [":p0 in (select value from json_each([table].[Availability+Info]))"], + ["yes"], + ), + ( + (("Availability+Info__arraynotcontains", "yes"),), + [":p0 not in (select value from json_each([table].[Availability+Info]))"], ["yes"], ), ],