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

Sub queries for is_in and not_in clause #785

Open
dantownsend opened this issue Mar 6, 2023 · 0 comments · May be fixed by #786
Open

Sub queries for is_in and not_in clause #785

dantownsend opened this issue Mar 6, 2023 · 0 comments · May be fixed by #786
Labels
enhancement New feature or request

Comments

@dantownsend
Copy link
Member

It will allow us to do this (using this example schema):

bands = await Band.objects().where(
    Band.id.is_in(
        Concert.select(Concert.band_1).where(
            Concert.starts_on > some_datetime
        )
    )
)

Currently it would be two separate queries, which isn't a huge hassle, but less efficient:

band_ids = await Concert.select(Concert.band_1).where(
    Concert.starts_on > some_datetime
).output(as_list=True)

bands = await Band.objects().where(
    Band.id.is_in(band_ids)
)

Adding this should be pretty straight forward. Here are the Postgres docs.

It's a very common use case which I come across all of the time.

@dantownsend dantownsend added the enhancement New feature or request label Mar 6, 2023
@dantownsend dantownsend added this to To do in Enhancements via automation Mar 6, 2023
@dantownsend dantownsend linked a pull request Mar 6, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Development

Successfully merging a pull request may close this issue.

1 participant