Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement __contains, __contained_by, __overlap and __len for ArrayField #1877

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

henadzit
Copy link
Contributor

@henadzit henadzit commented Feb 5, 2025

Description

Implements the following lookup types for ArrayField:

  • contains - await ArrayFields.filter(array__contains=[1, 2, 3]).first() which will use the @> operator
  • contained_by - will use the <@ operator
  • overlap - will use the && operator
  • len - will use the array_length function, e.g. await ArrayFields.filter(array__len=3).first()

Motivation and Context

This should close #1857 and #370.

The filters are modeled after Django's counterparts.

How Has This Been Tested?

make ci

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added the changelog accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Copy link

codspeed-hq bot commented Feb 5, 2025

CodSpeed Performance Report

Merging #1877 will not alter performance

Comparing henadzit:feat/array-filters (1169390) with develop (1d4d60b)

Summary

✅ 12 untouched benchmarks

@henadzit
Copy link
Contributor Author

henadzit commented Feb 5, 2025

The psycopg tests are failing with

psycopg.errors.UndefinedFunction: operator does not exist: integer[] <@ smallint[]
LINE 1: SELECT "array" "0" FROM "arrayfields" WHERE "array"<@$1

because psycopg is trying to use the smallest type possible... I need to think how to overcome this.

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.

Array filter for postgres
1 participant