Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#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 Austin Pua)

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 Austin Pua, 8 years ago

Description: modified (diff)

comment:2 by Austin Pua, 8 years ago

Version: 1.9rc1master

comment:3 by Tim Graham, 8 years ago

Cc: Marc Tamlyn added

Marc, any ideas about this?

comment:4 by Marc Tamlyn, 8 years ago

Resolution: worksforme
Status: newclosed
Type: UncategorizedCleanup/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 Austin Pua, 8 years ago

I was able to whip something up using the Expression API for the lookup, but it fails when I nest it inside an aggregate. 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! I will try to tinker with it some more.

Last edited 8 years ago by Austin Pua (previous) (diff)
Note: See TracTickets for help on using tickets.
Back to Top