MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / op

Method op

lib/sqlalchemy/sql/operators.py:207–312  ·  view source on GitHub ↗

Produce a generic operator function. e.g.:: somecolumn.op("*")(5) produces:: somecolumn * 5 This function can also be used to make bitwise operators explicit. For example:: somecolumn.op("&")(0xFF) is a bitwise AND of the v

(
        self,
        opstring: str,
        precedence: int = 0,
        is_comparison: bool = False,
        return_type: Optional[
            Union[Type[TypeEngine[Any]], TypeEngine[Any]]
        ] = None,
        python_impl: Optional[Callable[..., Any]] = None,
    )

Source from the content-addressed store, hash-verified

205 return self.operate(inv)
206
207 def op(
208 self,
209 opstring: str,
210 precedence: int = 0,
211 is_comparison: bool = False,
212 return_type: Optional[
213 Union[Type[TypeEngine[Any]], TypeEngine[Any]]
214 ] = None,
215 python_impl: Optional[Callable[..., Any]] = None,
216 ) -> Callable[[Any], Operators]:
217 """Produce a generic operator function.
218
219 e.g.::
220
221 somecolumn.op("*")(5)
222
223 produces::
224
225 somecolumn * 5
226
227 This function can also be used to make bitwise operators explicit. For
228 example::
229
230 somecolumn.op("&")(0xFF)
231
232 is a bitwise AND of the value in ``somecolumn``.
233
234 :param opstring: a string which will be output as the infix operator
235 between this element and the expression passed to the
236 generated function.
237
238 :param precedence: precedence which the database is expected to apply
239 to the operator in SQL expressions. This integer value acts as a hint
240 for the SQL compiler to know when explicit parenthesis should be
241 rendered around a particular operation. A lower number will cause the
242 expression to be parenthesized when applied against another operator
243 with higher precedence. The default value of ``0`` is lower than all
244 operators except for the comma (``,``) and ``AS`` operators. A value
245 of 100 will be higher or equal to all operators, and -100 will be
246 lower than or equal to all operators.
247
248 .. seealso::
249
250 :ref:`faq_sql_expression_op_parenthesis` - detailed description
251 of how the SQLAlchemy SQL compiler renders parenthesis
252
253 :param is_comparison: legacy; if True, the operator will be considered
254 as a "comparison" operator, that is which evaluates to a boolean
255 true/false value, like ``==``, ``>``, etc. This flag is provided
256 so that ORM relationships can establish that the operator is a
257 comparison operator when used in a custom join condition.
258
259 Using the ``is_comparison`` parameter is superseded by using the
260 :meth:`.Operators.bool_op` method instead; this more succinct
261 operator sets this parameter automatically, but also provides
262 correct :pep:`484` typing support as the returned object will
263 express a "boolean" datatype, i.e. ``BinaryExpression[bool]``.
264

Callers 15

bool_opMethod · 0.95
l2_distanceMethod · 0.45
inner_productMethod · 0.45
cosine_distanceMethod · 0.45
opFunction · 0.45
_assert_and_overrideMethod · 0.45
_assert_add_overrideMethod · 0.45
__add__Method · 0.45
__and__Method · 0.45
__add__Method · 0.45

Calls 1

custom_opClass · 0.85

Tested by 15

_assert_and_overrideMethod · 0.36
_assert_add_overrideMethod · 0.36
__add__Method · 0.36
__and__Method · 0.36
__add__Method · 0.36
__and__Method · 0.36
__add__Method · 0.36
__and__Method · 0.36
__add__Method · 0.36
__and__Method · 0.36