class _FunctionGenerator: (source)
Generate SQL function expressions. :data:`.func` is a special object instance which generates SQL functions based on name-based attributes, e.g.: .. sourcecode:: pycon+sql >>> print(func.count(1)) {printsql}count(:param_1) The returned object is an instance of :class:`.Function`, and is a column-oriented SQL element like any other, and is used in that way: .. sourcecode:: pycon+sql >>> print(select(func.count(table.c.id))) {printsql}SELECT count(sometable.id) FROM sometable Any name can be given to :data:`.func`. If the function name is unknown to SQLAlchemy, it will be rendered exactly as is. For common SQL functions which SQLAlchemy is aware of, the name may be interpreted as a *generic function* which will be compiled appropriately to the target database: .. sourcecode:: pycon+sql >>> print(func.current_timestamp()) {printsql}CURRENT_TIMESTAMP To call functions which are present in dot-separated packages, specify them in the same manner: .. sourcecode:: pycon+sql >>> print(func.stats.yield_curve(5, 10)) {printsql}stats.yield_curve(:yield_curve_1, :yield_curve_2) SQLAlchemy can be made aware of the return type of functions to enable type-specific lexical and result-based behavior. For example, to ensure that a string-based function returns a Unicode value and is similarly treated as a string in expressions, specify :class:`~sqlalchemy.types.Unicode` as the type: .. sourcecode:: pycon+sql >>> print(func.my_string(u'hi', type_=Unicode) + ' ' + ... func.my_string(u'there', type_=Unicode)) {printsql}my_string(:my_string_1) || :my_string_2 || my_string(:my_string_3) The object returned by a :data:`.func` call is usually an instance of :class:`.Function`. This object meets the "column" interface, including comparison and labeling functions. The object can also be passed the :meth:`~.Connectable.execute` method of a :class:`_engine.Connection` or :class:`_engine.Engine`, where it will be wrapped inside of a SELECT statement first:: print(connection.execute(func.current_timestamp()).scalar()) In a few exception cases, the :data:`.func` accessor will redirect a name to a built-in expression such as :func:`.cast` or :func:`.extract`, as these names have well-known meaning but are not exactly the same as "functions" from a SQLAlchemy perspective. Functions which are interpreted as "generic" functions know how to calculate their return type automatically. For a listing of known generic functions, see :ref:`generic_functions`. .. note:: The :data:`.func` construct has only limited support for calling standalone "stored procedures", especially those with special parameterization concerns. See the section :ref:`stored_procedures` for details on how to use the DBAPI-level ``callproc()`` method for fully traditional stored procedures. .. seealso:: :ref:`tutorial_functions` - in the :ref:`unified_tutorial` :class:`.Function`
Method | __call__ |
Undocumented |
Method | __getattr__ |
Undocumented |
Method | __init__ |
Undocumented |
Instance Variable | opts |
Undocumented |
Property | ansifunction |
Undocumented |
Property | array |
Undocumented |
Property | cast |
Undocumented |
Property | char |
Undocumented |
Property | coalesce |
Undocumented |
Property | concat |
Undocumented |
Property | count |
Undocumented |
Property | cube |
Undocumented |
Property | cume |
Undocumented |
Property | current |
Undocumented |
Property | current |
Undocumented |
Property | current |
Undocumented |
Property | current |
Undocumented |
Property | dense |
Undocumented |
Property | extract |
Undocumented |
Property | grouping |
Undocumented |
Property | localtime |
Undocumented |
Property | localtimestamp |
Undocumented |
Property | max |
Undocumented |
Property | min |
Undocumented |
Property | mode |
Undocumented |
Property | next |
Undocumented |
Property | now |
Undocumented |
Property | orderedsetagg |
Undocumented |
Property | percent |
Undocumented |
Property | percentile |
Undocumented |
Property | percentile |
Undocumented |
Property | random |
Undocumented |
Property | rank |
Undocumented |
Property | returntypefromargs |
Undocumented |
Property | rollup |
Undocumented |
Property | session |
Undocumented |
Property | sum |
Undocumented |
Property | sysdate |
Undocumented |
Property | user |
Undocumented |
Instance Variable | __names |
Undocumented |