FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add `ArrayOverlap` function (`&&`) by regiscamimura · Pull Request #1422 · piccolo-orm/piccolo · GitHub

Add ArrayOverlap function (&&) - #1422

Open
regiscamimura wants to merge 1 commit into
piccolo-orm:masterfrom
regiscamimura:array-overlap
Open

Add ArrayOverlap function (&&)#1422
regiscamimura wants to merge 1 commit into
piccolo-orm:masterfrom
regiscamimura:array-overlap

Conversation

Copy link
Copy Markdown

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.

from piccolo.query.functions import ArrayOverlap

await Ticket.select().where(
    ArrayOverlap(Ticket.seat_numbers, [510, 511])
)

There's also a column method, matching cat / remove / append / prepend /
replace:

await Ticket.select().where(Ticket.seat_numbers.overlap([510, 511]))

Notes

  • 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:

$ ./scripts/test-postgres.sh tests/columns/test_array.py
18 passed, 6 skipped

$ ./scripts/test-sqlite.sh tests/columns/test_array.py
12 passed, 12 skipped

I don't have a CockroachDB instance to hand, so that path is untested beyond
following the existing convention.

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
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.

1 participant


Back | FazBrowse Home | New Git URL