Provides =ANY(ARRAY(xxx)) instead of IN (xxx)
Project description
Provides =ANY(ARRAY(xxx)) instead of IN (xxx)
Documentation
This library is designed for Postgres. It enables developers to cope with problem when Postgres doesn’t use indexes with long IN () statements.
Usually, when you try to do a query:
SELECT a.* FROM a
WHERE a.id NOT IN (
SELECT b.id FROM b
)
You expect that it will be used index on a.id. Unfortunately, it doesn’t work.
There is a trick to make Postgres do it by rewritten query this way:
SELECT a.* FROM a
WHERE a.id=ANY(ARRAY(SELECT b.id FROM b))
This library allows you to use this statement. Examples:
"""
SELECT * FROM mymodel WHERE somefield=ANY([1, 2, 3])
"""
MyModel.objects.filter(somefield__any_arr=[1, 2, 3])
"""
SELECT * FROM mymodel WHERE somefield=ANY(ARRAY(SELECT somefield FROM modelb))
"""
subquery = Subquery(model_b__instances.values('somefield'))
MyModel.objects.filter(somefield__any=subquery)
Quickstart
Install django-postgres-lookups-any:
pip install django-postges-lookups-any
Add it to your INSTALLED_APPS:
INSTALLED_APPS = (
...
'django_postges_lookups_any',
...
)
Running Tests
Does the code actually work?
source <YOURVIRTUALENV>/bin/activate (myenv) $ pip install -r requirements_test.txt (myenv) $ pytest
Development commands
pip install -r requirements_dev.txt
Credits
Tools used in rendering this package:
History
0.1.0 (2021-02-08)
First release on PyPI.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-postges-lookups-any-0.1.0.tar.gz
.
File metadata
- Download URL: django-postges-lookups-any-0.1.0.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4add93a071f84a35175a0324e28d698dd3c6ddbdc9f131903491ffa02c3e306a |
|
MD5 | 68c8e55d7481c132219addba4b8ba096 |
|
BLAKE2b-256 | de03dd9d4a047c690c1c05ef409e9cdc80f0191a69d2eee5e53adb28b0e74184 |
File details
Details for the file django_postges_lookups_any-0.1.0-py2.py3-none-any.whl
.
File metadata
- Download URL: django_postges_lookups_any-0.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 178c85d72fec035879c151d29f1aa44b223d1cd305355c4531a9bcf36245600b |
|
MD5 | cad241bfa11f199ef47400074b6a7c4a |
|
BLAKE2b-256 | afc8b380c20450f5d4ad1103232e0fac99208e7a6328e0c80cd224c64b3a8d20 |