piccolo.query.functions.array covers array_cat, array_append,
array_prepend, array_replace and array_remove, but not the && overlap
operator.
The gap it fills: "does this array contain any of these values?". Today that has
to be written as an OR of any() calls, one per value, which can't use a GIN
index. && is a single indexable test.
Postgres / CockroachDB only, raising the same ValueError on SQLite as the
other array functions.
ArrayOverlap subclasses QueryString rather than ArrayQueryString —
ArrayQueryString overrides __add__ / __radd__ to mean concatenation,
which doesn't apply here as && returns a boolean, not an array.
On CockroachDB the array needs an explicit type, the same as any() /
not_any() — the tests use QueryString("{}::INTEGER[]", [...]) for that
reason. On Postgres a plain list works, since the type is inferred from the
column.
Testing
Added test_overlap, test_overlap_plain_list, test_overlap_two_columns and
test_overlap_sqlite to tests/columns/test_array.py:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
piccolo.query.functions.array covers array_cat, array_append,
array_prepend, array_replace and array_remove, but not the && overlap
operator.
The gap it fills: "does this array contain any of these values?". Today that has
to be written as an OR of any() calls, one per value, which can't use a GIN
index. && is a single indexable test.
There's also a column method, matching cat / remove / append / prepend /
replace:
Notes
other array functions.
ArrayQueryString overrides __add__ / __radd__ to mean concatenation,
which doesn't apply here as && returns a boolean, not an array.
not_any() — the tests use QueryString("{}::INTEGER[]", [...]) for that
reason. On Postgres a plain list works, since the type is inferred from the
column.
Testing
Added test_overlap, test_overlap_plain_list, test_overlap_two_columns and
test_overlap_sqlite to tests/columns/test_array.py:
I don't have a CockroachDB instance to hand, so that path is untested beyond
following the existing convention.