Implement the ``in`` operator. In a column context, produces the clause ``column IN ``. 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 ite
(self, other: Any)
| 842 | return self.operate(bitwise_rshift_op, other) |
| 843 | |
| 844 | def in_(self, other: Any) -> ColumnOperators: |
| 845 | """Implement the ``in`` operator. |
| 846 | |
| 847 | In a column context, produces the clause ``column IN <other>``. |
| 848 | |
| 849 | The given parameter ``other`` may be: |
| 850 | |
| 851 | * A list of literal values, |
| 852 | e.g.:: |
| 853 | |
| 854 | stmt.where(column.in_([1, 2, 3])) |
| 855 | |
| 856 | In this calling form, the list of items is converted to a set of |
| 857 | bound parameters the same length as the list given: |
| 858 | |
| 859 | .. sourcecode:: sql |
| 860 | |
| 861 | WHERE COL IN (?, ?, ?) |
| 862 | |
| 863 | * A list of tuples may be provided if the comparison is against a |
| 864 | :func:`.tuple_` containing multiple expressions:: |
| 865 | |
| 866 | from sqlalchemy import tuple_ |
| 867 | |
| 868 | stmt.where(tuple_(col1, col2).in_([(1, 10), (2, 20), (3, 30)])) |
| 869 | |
| 870 | * An empty list, |
| 871 | e.g.:: |
| 872 | |
| 873 | stmt.where(column.in_([])) |
| 874 | |
| 875 | In this calling form, the expression renders an "empty set" |
| 876 | expression. These expressions are tailored to individual backends |
| 877 | and are generally trying to get an empty SELECT statement as a |
| 878 | subquery. Such as on SQLite, the expression is: |
| 879 | |
| 880 | .. sourcecode:: sql |
| 881 | |
| 882 | WHERE col IN (SELECT 1 FROM (SELECT 1) WHERE 1!=1) |
| 883 | |
| 884 | .. versionchanged:: 1.4 empty IN expressions now use an |
| 885 | execution-time generated SELECT subquery in all cases. |
| 886 | |
| 887 | * A bound parameter, e.g. :func:`.bindparam`, may be used if it |
| 888 | includes the :paramref:`.bindparam.expanding` flag:: |
| 889 | |
| 890 | stmt.where(column.in_(bindparam("value", expanding=True))) |
| 891 | |
| 892 | In this calling form, the expression renders a special non-SQL |
| 893 | placeholder expression that looks like: |
| 894 | |
| 895 | .. sourcecode:: sql |
| 896 | |
| 897 | WHERE COL IN ([EXPANDING_value]) |
| 898 | |
| 899 | This placeholder expression is intercepted at statement execution |
| 900 | time to be converted into the variable number of bound parameter |
| 901 | form illustrated earlier. If the statement were executed as:: |