Fixed #20561 -- Emphasized that QuerySet.distinct([*fields]) is only supported by Postgres.

Thanks jtiai for the suggestion.
This commit is contained in:
Tim Graham 2013-07-05 07:20:05 -04:00
parent b9fceadfd4
commit 577b0f9189
1 changed files with 5 additions and 8 deletions

View File

@ -379,16 +379,13 @@ query spans multiple tables, it's possible to get duplicate results when a
:meth:`values()` together, be careful when ordering by fields not in the :meth:`values()` together, be careful when ordering by fields not in the
:meth:`values()` call. :meth:`values()` call.
You can pass positional arguments (``*fields``) in order to specify the names On PostgreSQL only, you can pass positional arguments (``*fields``) in order to
of fields to which the ``DISTINCT`` should apply. This translates to a specify the names of fields to which the ``DISTINCT`` should apply. This
``SELECT DISTINCT ON`` SQL query. Here's the difference. For a normal translates to a ``SELECT DISTINCT ON`` SQL query. Here's the difference. For a
``distinct()`` call, the database compares *each* field in each row when normal ``distinct()`` call, the database compares *each* field in each row when
determining which rows are distinct. For a ``distinct()`` call with specified determining which rows are distinct. For a ``distinct()`` call with specified
field names, the database will only compare the specified field names. field names, the database will only compare the specified field names.
.. note::
This ability to specify field names is only available in PostgreSQL.
.. note:: .. note::
When you specify field names, you *must* provide an ``order_by()`` in the When you specify field names, you *must* provide an ``order_by()`` in the
QuerySet, and the fields in ``order_by()`` must start with the fields in QuerySet, and the fields in ``order_by()`` must start with the fields in
@ -398,7 +395,7 @@ field names, the database will only compare the specified field names.
value in column ``a``. If you don't specify an order, you'll get some value in column ``a``. If you don't specify an order, you'll get some
arbitrary row. arbitrary row.
Examples:: Examples (those after the first will only work on PostgreSQL)::
>>> Author.objects.distinct() >>> Author.objects.distinct()
[...] [...]