Participer au site avec un Tip
Rechercher
 

Améliorations / Corrections

Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.

Emplacement :

Description des améliorations :

Vous êtes un professionnel et vous avez besoin d'une formation ? Coder avec une
Intelligence Artificielle
Voir le programme détaillé
Module « sqlalchemy »

Fonction distinct - module sqlalchemy

Signature de la fonction distinct

def distinct(expr: '_ColumnExpressionArgument[_T]') -> 'UnaryExpression[_T]' 

Description

help(sqlalchemy.distinct)

Produce an column-expression-level unary ``DISTINCT`` clause.

This applies the ``DISTINCT`` keyword to an **individual column
expression** (e.g. not the whole statement), and renders **specifically
in that column position**; this is used for containment within
an aggregate function, as in::

    from sqlalchemy import distinct, func

    stmt = select(users_table.c.id, func.count(distinct(users_table.c.name)))

The above would produce an statement resembling:

.. sourcecode:: sql

    SELECT user.id, count(DISTINCT user.name) FROM user

.. tip:: The :func:`_sql.distinct` function does **not** apply DISTINCT
   to the full SELECT statement, instead applying a DISTINCT modifier
   to **individual column expressions**.  For general ``SELECT DISTINCT``
   support, use the
   :meth:`_sql.Select.distinct` method on :class:`_sql.Select`.

The :func:`.distinct` function is also available as a column-level
method, e.g. :meth:`_expression.ColumnElement.distinct`, as in::

    stmt = select(func.count(users_table.c.name.distinct()))

The :func:`.distinct` operator is different from the
:meth:`_expression.Select.distinct` method of
:class:`_expression.Select`,
which produces a ``SELECT`` statement
with ``DISTINCT`` applied to the result set as a whole,
e.g. a ``SELECT DISTINCT`` expression.  See that method for further
information.

.. seealso::

    :meth:`_expression.ColumnElement.distinct`

    :meth:`_expression.Select.distinct`

    :data:`.func`



Vous êtes un professionnel et vous avez besoin d'une formation ? Deep Learning avec Python
et Keras et Tensorflow
Voir le programme détaillé