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

add unique select #22

Closed
Jaymon opened this issue Apr 15, 2016 · 3 comments
Closed

add unique select #22

Jaymon opened this issue Apr 15, 2016 · 3 comments

Comments

@Jaymon
Copy link
Owner

Jaymon commented Apr 15, 2016

Foo.unique("bar_id").gt__created(now - ago).lt__created(now).values()

Would result in:

SELECT DISTINCT bar_id WHERE _created > ... AND _created < ...
@Jaymon
Copy link
Owner Author

Jaymon commented Apr 16, 2016

I added this one other time and then ended up removing it and I couldn't remember why because it was a few years ago but now I remember:

for SELECT DISTINCT, ORDER BY expressions must appear in select list

So if you want to say, get all the distinct foos that were active between January and March, you can't do a query like:

Activity.query.unique_foo().gt__created(january).lt__created(march).values()

Because it needs _created to be in the SELECT portion of the query (and the memories come flooding back), and if you add _created to the fields list like this: DISTINCT foo, _created it returns unique foo, _created pairs, which is almost never want I want.

@Jaymon
Copy link
Owner Author

Jaymon commented Apr 19, 2016

This has been added but I'm not happy with the implementation, at this point it is buried in the Fields.options instance and so it's not very discoverable for later interfaces. The question is should this be made a first class method like count(), get(), and get_one()?

Basically I'm going to leave this open for a bit while I decide what is the best long term implementation.

@Jaymon
Copy link
Owner Author

Jaymon commented Oct 16, 2021

I added Query.distinct() that you could do to mark all the selected fields as distinct/unique

@Jaymon Jaymon closed this as completed Oct 16, 2021
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

No branches or pull requests

1 participant