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 « ColumnOperators »

Méthode sqlalchemy.ColumnOperators.in_

Signature de la méthode in_

def in_(self, other: 'Any') -> 'ColumnOperators' 

Description

help(ColumnOperators.in_)

Implement the ``in`` operator.

In a column context, produces the clause ``column IN <other>``.

The given parameter ``other`` may be:

* A list of literal values,
  e.g.::

    stmt.where(column.in_([1, 2, 3]))

  In this calling form, the list of items is converted to a set of
  bound parameters the same length as the list given:

  .. sourcecode:: sql

    WHERE COL IN (?, ?, ?)

* A list of tuples may be provided if the comparison is against a
  :func:`.tuple_` containing multiple expressions::

    from sqlalchemy import tuple_

    stmt.where(tuple_(col1, col2).in_([(1, 10), (2, 20), (3, 30)]))

* An empty list,
  e.g.::

    stmt.where(column.in_([]))

  In this calling form, the expression renders an "empty set"
  expression.  These expressions are tailored to individual backends
  and are generally trying to get an empty SELECT statement as a
  subquery.  Such as on SQLite, the expression is:

  .. sourcecode:: sql

    WHERE col IN (SELECT 1 FROM (SELECT 1) WHERE 1!=1)

  .. versionchanged:: 1.4  empty IN expressions now use an
     execution-time generated SELECT subquery in all cases.

* A bound parameter, e.g. :func:`.bindparam`, may be used if it
  includes the :paramref:`.bindparam.expanding` flag::

    stmt.where(column.in_(bindparam("value", expanding=True)))

  In this calling form, the expression renders a special non-SQL
  placeholder expression that looks like:

  .. sourcecode:: sql

    WHERE COL IN ([EXPANDING_value])

  This placeholder expression is intercepted at statement execution
  time to be converted into the variable number of bound parameter
  form illustrated earlier.   If the statement were executed as::

    connection.execute(stmt, {"value": [1, 2, 3]})

  The database would be passed a bound parameter for each value:

  .. sourcecode:: sql

    WHERE COL IN (?, ?, ?)

  .. versionadded:: 1.2 added "expanding" bound parameters

  If an empty list is passed, a special "empty list" expression,
  which is specific to the database in use, is rendered.  On
  SQLite this would be:

  .. sourcecode:: sql

    WHERE COL IN (SELECT 1 FROM (SELECT 1) WHERE 1!=1)

  .. versionadded:: 1.3 "expanding" bound parameters now support
     empty lists

* a :func:`_expression.select` construct, which is usually a
  correlated scalar select::

    stmt.where(
        column.in_(select(othertable.c.y).where(table.c.x == othertable.c.x))
    )

  In this calling form, :meth:`.ColumnOperators.in_` renders as given:

  .. sourcecode:: sql

    WHERE COL IN (SELECT othertable.y
    FROM othertable WHERE othertable.x = table.x)

:param other: a list of literals, a :func:`_expression.select`
 construct, or a :func:`.bindparam` construct that includes the
 :paramref:`.bindparam.expanding` flag set to True.



Vous êtes un professionnel et vous avez besoin d'une formation ? Machine Learning
avec Scikit-Learn
Voir le programme détaillé