Opened 4 years ago
Closed 4 years ago
#32169 closed New feature (fixed)
Added distinct support for JSONBAgg
Reported by: | Chiorufarewerin | Owned by: | Chiorufarewerin |
---|---|---|---|
Component: | contrib.postgres | Version: | dev |
Severity: | Normal | Keywords: | jsonbagg |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I often use JSONBAgg and when there are several aggregates, contains duplicates.
class Author(models.Model): name = models.CharField(max_length=50) alias = models.CharField(max_length=50, null=True, blank=True) age = models.PositiveSmallIntegerField(default=30) class Article(models.Model): authors = models.ManyToManyField(Author, related_name='articles') title = models.CharField(max_length=50) class Product(models.Model): article = models.ForeignKey(Article, related_name='products', on_delete=models.CASCADE) name = models.CharField(max_length=255) Article.objects.annotate( authors_json=ArrayAgg( Func( Value('name'), 'authors__name', Value('alias'), 'authors__alias', function='jsonb_build_object' ), distinct=True, ), products_json=ArrayAgg( Func( Value('name'), 'products__name', function='jsonb_build_object' ), distinct=True, ), )
Change History (3)
comment:1 by , 4 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 4 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:3 by , 4 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Note:
See TracTickets
for help on using tickets.
In 18c8ced8: