#25828 closed Cleanup/optimization (worksforme)
Aggregation and annotation using a postgres JSONField
Reported by: | Austin Pua | Owned by: | |
---|---|---|---|
Component: | contrib.postgres | Version: | dev |
Severity: | Normal | Keywords: | JSONField aggregation annotation |
Cc: | Marc Tamlyn | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
I saw this StackOverflow post, and I decided to try it out myself. I can confirm that aggregations and annotations do not work with JSONField
. Using values()
also does not work. I think it has something to do with how the strings/lookups are parsed.
Is this a bug that can/will be fixed before the official 1.9 release, or is this a feature enhancement for future versions? Is it even possible to implement?
Change History (5)
comment:1 by , 9 years ago
Description: | modified (diff) |
---|
comment:2 by , 9 years ago
Version: | 1.9rc1 → master |
---|
comment:3 by , 9 years ago
Cc: | added |
---|
comment:4 by , 9 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
Type: | Uncategorized → Cleanup/optimization |
This would be about supporting generic __
lookups in more places. It's not a bug, it's a known restriction of the API for values()
and annotate()
. Now that transforms are expressions, it's possible that something like this should work:
.annotate(Avg(KeyLookup('key_name', 'field_name')))
but I haven't tried it, so syntax might not be quite right there. I believe that annotate
works and values
does not, but I may be wrong.
In any case, annotation first and then using that annotation later will generally allow more complex queries than you can use directly.
I'm going to close this for now as the expansion of the ORM to cover things like this does not need another ticket. If you can't find a way to make the above work (or similar) let me know.
comment:5 by , 9 years ago
I was able to whip something up using the Expression
API. It feels a bit hackish and not Django-ish. The docs can use some more examples and more info on the process flow though. Anyway, thanks for pointing me in the right direction!
Marc, any ideas about this?