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 ? Sensibilisation à
l'Intelligence Artificielle
Voir le programme détaillé
Classe « Result »

Méthode sqlalchemy.Result.unique

Signature de la méthode unique

def unique(self, strategy: 'Optional[_UniqueFilterType]' = None) -> 'Self' 

Description

help(Result.unique)

Apply unique filtering to the objects returned by this
:class:`_engine.Result`.

When this filter is applied with no arguments, the rows or objects
returned will filtered such that each row is returned uniquely. The
algorithm used to determine this uniqueness is by default the Python
hashing identity of the whole tuple.   In some cases a specialized
per-entity hashing scheme may be used, such as when using the ORM, a
scheme is applied which  works against the primary key identity of
returned objects.

The unique filter is applied **after all other filters**, which means
if the columns returned have been refined using a method such as the
:meth:`_engine.Result.columns` or :meth:`_engine.Result.scalars`
method, the uniquing is applied to **only the column or columns
returned**.   This occurs regardless of the order in which these
methods have been called upon the :class:`_engine.Result` object.

The unique filter also changes the calculus used for methods like
:meth:`_engine.Result.fetchmany` and :meth:`_engine.Result.partitions`.
When using :meth:`_engine.Result.unique`, these methods will continue
to yield the number of rows or objects requested, after uniquing
has been applied.  However, this necessarily impacts the buffering
behavior of the underlying cursor or datasource, such that multiple
underlying calls to ``cursor.fetchmany()`` may be necessary in order
to accumulate enough objects in order to provide a unique collection
of the requested size.

:param strategy: a callable that will be applied to rows or objects
 being iterated, which should return an object that represents the
 unique value of the row.   A Python ``set()`` is used to store
 these identities.   If not passed, a default uniqueness strategy
 is used which may have been assembled by the source of this
 :class:`_engine.Result` object.



Vous êtes un professionnel et vous avez besoin d'une formation ? Programmation Python
Les fondamentaux
Voir le programme détaillé