Monday, November 26, 2018

Max function and grouping with Oracle

I have a parent model that has a relationship to some data that is changing:


class Parent(models.Model):
     name = models.CharField(...)
     created_timestamp = models.DateTimeField(auto_now_add=True, null=True)
     updated_timestamp = models.DateTimeField(auto_now=True, null=True)


class Child(models.Model):
     parent = models.ForeignKey(Parent, on_delete=models.CASCADE)
     created_timestamp = models.DateTimeField(auto_now_add=True, null=True)
     updated_timestamp = models.DateTimeField(auto_now=True, null=True)


I am trying to annotate a query with a Max updated_timestamp for the children:

Parent.objects.annotate(child_updated_timestamp=models.Max('child__updated_timestamp', output_field=models.DateTimeField()))

It seems like Oracle backend is attempting to GROUP BY every field in the child model.

Can anyone tell me whether they've seen anything like this and how to constrain the GROUP BY?

Thanks,

-Dan


     
    

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4a41b74a-a51b-4282-b292-2e6a59fe1bd7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment