Skip to content

Commit

Permalink
Fixed #34199 -- Added documentation for StringAgg
Browse files Browse the repository at this point in the history
  • Loading branch information
sdolemelipone committed Dec 3, 2022
1 parent eccda63 commit 078f44c
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions docs/ref/contrib/postgres/aggregates.txt
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,31 @@ General-purpose aggregation functions

Examples are the same as for :attr:`ArrayAgg.ordering`.

Usage example::

class Publication(models.Model):
title = models.CharField(max_length=30)

class Article(model.Model):
headline = models.CharField(max_length=100)
publications = models.ManyToManyField(Publication)

>>> article = Article.objects.create(headline='NASA uses Python')
>>> article.publications.create(title='The Python Journal')
>>> article.publications.create(title='Science News')

>>> from django.contrib.postgres.aggregates import StringAgg
>>> Article.objects.annotate(
... publication_names=StringAgg(
... 'publications__title',
... delimiter=', ',
... ordering='publications__title',
... )
... ).values('headline', 'publication_names')
<QuerySet [{
'headline': 'NASA uses Python', 'publication_names': 'Science News, The Python Journal'
]}]>

.. deprecated:: 4.0

If there are no rows and ``default`` is not provided, ``StringAgg``
Expand Down

0 comments on commit 078f44c

Please sign in to comment.