Opened 10 years ago
Closed 10 years ago
#22696 closed New feature (wontfix)
Support for DISTINCT ON in sqlite3
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
.distinct() raises NotImplementedError when using sqlite3 backend. Maybe DISTINCT ON could be implemented like this?
Note:
See TracTickets
for help on using tickets.
I'm personally not a fan of introducing such hack to the ORM. IMHO, sticking to the native features of the backends will keep the codebase cleaner and more robust. So since SQLite3 doesn't support DISTINCT ON fields, I don't think implementing this workaround is a good idea.
Having said that, if you need a distinct on field query, you can implement it through the QuerySet API, using a combination of
values().distinct()
orvalues().annotate()
, here's a simple example:This is roughly equivalent to using
distinct on (first_name)
with anorder by last_name
.If you still think this is a good idea, you could get more attention and discussion by using Django developers mailing list (http://groups.google.com/group/django-developers/).
Thanks.