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é
Module « sqlalchemy »

Fonction exists - module sqlalchemy

Signature de la fonction exists

def exists(__argument: 'Optional[Union[_ColumnsClauseArgument[Any], SelectBase, ScalarSelect[Any]]]' = None) -> 'Exists' 

Description

help(sqlalchemy.exists)

Construct a new :class:`_expression.Exists` construct.

The :func:`_sql.exists` can be invoked by itself to produce an
:class:`_sql.Exists` construct, which will accept simple WHERE
criteria::

    exists_criteria = exists().where(table1.c.col1 == table2.c.col2)

However, for greater flexibility in constructing the SELECT, an
existing :class:`_sql.Select` construct may be converted to an
:class:`_sql.Exists`, most conveniently by making use of the
:meth:`_sql.SelectBase.exists` method::

    exists_criteria = (
        select(table2.c.col2).where(table1.c.col1 == table2.c.col2).exists()
    )

The EXISTS criteria is then used inside of an enclosing SELECT::

    stmt = select(table1.c.col1).where(exists_criteria)

The above statement will then be of the form:

.. sourcecode:: sql

    SELECT col1 FROM table1 WHERE EXISTS
    (SELECT table2.col2 FROM table2 WHERE table2.col2 = table1.col1)

.. seealso::

    :ref:`tutorial_exists` - in the :term:`2.0 style` tutorial.

    :meth:`_sql.SelectBase.exists` - method to transform a ``SELECT`` to an
    ``EXISTS`` clause.



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