Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
df8412d2
Kaydet (Commit)
df8412d2
authored
May 15, 2016
tarafından
Rustam Kashapov
Kaydeden (comit)
Tim Graham
Haz 02, 2016
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #26617 -- Added distinct argument to contrib.postgres's StringAgg.
üst
149ace94
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
5 deletions
+33
-5
general.py
django/contrib/postgres/aggregates/general.py
+4
-3
aggregates.txt
docs/ref/contrib/postgres/aggregates.txt
+8
-1
1.11.txt
docs/releases/1.11.txt
+3
-1
test_aggregates.py
tests/postgres_tests/test_aggregates.py
+18
-0
No files found.
django/contrib/postgres/aggregates/general.py
Dosyayı görüntüle @
df8412d2
...
...
@@ -32,10 +32,11 @@ class BoolOr(Aggregate):
class
StringAgg
(
Aggregate
):
function
=
'STRING_AGG'
template
=
"
%(function)
s(
%(expressions)
s, '
%(delimiter)
s')"
template
=
"
%(function)
s(
%(
distinct)
s
%(
expressions)
s, '
%(delimiter)
s')"
def
__init__
(
self
,
expression
,
delimiter
,
**
extra
):
super
(
StringAgg
,
self
)
.
__init__
(
expression
,
delimiter
=
delimiter
,
**
extra
)
def
__init__
(
self
,
expression
,
delimiter
,
distinct
=
False
,
**
extra
):
distinct
=
'DISTINCT '
if
distinct
else
''
super
(
StringAgg
,
self
)
.
__init__
(
expression
,
delimiter
=
delimiter
,
distinct
=
distinct
,
**
extra
)
def
convert_value
(
self
,
value
,
expression
,
connection
,
context
):
if
not
value
:
...
...
docs/ref/contrib/postgres/aggregates.txt
Dosyayı görüntüle @
df8412d2
...
...
@@ -61,7 +61,7 @@ General-purpose aggregation functions
``StringAgg``
-------------
.. class:: StringAgg(expression, delimiter)
.. class:: StringAgg(expression, delimiter
, distinct=False
)
Returns the input values concatenated into a string, separated by
the ``delimiter`` string.
...
...
@@ -70,6 +70,13 @@ General-purpose aggregation functions
Required argument. Needs to be a string.
.. attribute:: distinct
.. versionadded:: 1.11
An optional boolean argument that determines if concatenated values
will be distinct. Defaults to ``False``.
Aggregate functions for statistics
==================================
...
...
docs/releases/1.11.txt
Dosyayı görüntüle @
df8412d2
...
...
@@ -81,7 +81,9 @@ Minor features
:mod:`django.contrib.postgres`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* ...
* The new ``distinct`` argument for
:class:`~django.contrib.postgres.aggregates.StringAgg` determines if
concatenated values will be distinct.
:mod:`django.contrib.redirects`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
...
tests/postgres_tests/test_aggregates.py
Dosyayı görüntüle @
df8412d2
...
...
@@ -111,6 +111,24 @@ class TestGeneralAggregate(PostgreSQLTestCase):
self
.
assertEqual
(
values
,
{
'stringagg'
:
''
})
class
TestStringAggregateDistinct
(
PostgreSQLTestCase
):
@classmethod
def
setUpTestData
(
cls
):
AggregateTestModel
.
objects
.
create
(
char_field
=
'Foo'
)
AggregateTestModel
.
objects
.
create
(
char_field
=
'Foo'
)
AggregateTestModel
.
objects
.
create
(
char_field
=
'Bar'
)
def
test_string_agg_distinct_false
(
self
):
values
=
AggregateTestModel
.
objects
.
aggregate
(
stringagg
=
StringAgg
(
'char_field'
,
delimiter
=
' '
,
distinct
=
False
))
self
.
assertEqual
(
values
[
'stringagg'
]
.
count
(
'Foo'
),
2
)
self
.
assertEqual
(
values
[
'stringagg'
]
.
count
(
'Bar'
),
1
)
def
test_string_agg_distinct_true
(
self
):
values
=
AggregateTestModel
.
objects
.
aggregate
(
stringagg
=
StringAgg
(
'char_field'
,
delimiter
=
' '
,
distinct
=
True
))
self
.
assertEqual
(
values
[
'stringagg'
]
.
count
(
'Foo'
),
1
)
self
.
assertEqual
(
values
[
'stringagg'
]
.
count
(
'Bar'
),
1
)
class
TestStatisticsAggregate
(
PostgreSQLTestCase
):
@classmethod
def
setUpTestData
(
cls
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment