﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
32169	Added distinct support for JSONBAgg	Chiorufarewerin	Chiorufarewerin	"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,
     ),
)
}}}
"	New feature	closed	contrib.postgres	dev	Normal	fixed	jsonbagg		Ready for checkin	1	0	0	0	0	0
