class documentation

class GenericFunction(util.with_metaclass(_GenericMeta, Function)):

Known subclasses: sqlalchemy.dialects.postgresql.hstore.hstore, sqlalchemy.sql.functions.AnsiFunction, sqlalchemy.sql.functions.array_agg, sqlalchemy.sql.functions.char_length, sqlalchemy.sql.functions.concat, sqlalchemy.sql.functions.count, sqlalchemy.sql.functions.cube, sqlalchemy.sql.functions.cume_dist, sqlalchemy.sql.functions.dense_rank, sqlalchemy.sql.functions.grouping_sets, sqlalchemy.sql.functions.next_value, sqlalchemy.sql.functions.now, sqlalchemy.sql.functions.OrderedSetAgg, sqlalchemy.sql.functions.percent_rank, sqlalchemy.sql.functions.random, sqlalchemy.sql.functions.rank, sqlalchemy.sql.functions.ReturnTypeFromArgs, sqlalchemy.sql.functions.rollup, sqlalchemy.dialects.postgresql.hstore._HStoreArrayFunction, sqlalchemy.dialects.postgresql.hstore._HStoreDefinedFunction, sqlalchemy.dialects.postgresql.hstore._HStoreDeleteFunction, sqlalchemy.dialects.postgresql.hstore._HStoreKeysFunction, sqlalchemy.dialects.postgresql.hstore._HStoreMatrixFunction, sqlalchemy.dialects.postgresql.hstore._HStoreSliceFunction, sqlalchemy.dialects.postgresql.hstore._HStoreValsFunction

View In Hierarchy

Define a 'generic' function.

A generic function is a pre-established .Function class that is instantiated automatically when called by name from the .func attribute. Note that calling any name from .func has the effect that a new .Function instance is created automatically, given that name. The primary use case for defining a .GenericFunction class is so that a function of a particular name may be given a fixed return type. It can also include custom argument parsing schemes as well as additional methods.

Subclasses of .GenericFunction are automatically registered under the name of the class. For example, a user-defined function as_utc() would be available immediately:

from sqlalchemy.sql.functions import GenericFunction
from sqlalchemy.types import DateTime

class as_utc(GenericFunction):
    type = DateTime
    inherit_cache = True

print(select(func.as_utc()))

User-defined generic functions can be organized into packages by specifying the "package" attribute when defining .GenericFunction. Third party libraries containing many functions may want to use this in order to avoid name conflicts with other systems. For example, if our as_utc() function were part of a package "time":

class as_utc(GenericFunction):
    type = DateTime
    package = "time"
    inherit_cache = True

The above function would be available from .func using the package name time:

print(select(func.time.as_utc()))

A final option is to allow the function to be accessed from one name in .func but to render as a different name. The identifier attribute will override the name used to access the function as loaded from .func, but will retain the usage of name as the rendered name:

class GeoBuffer(GenericFunction):
    type = Geometry
    package = "geo"
    name = "ST_Buffer"
    identifier = "buffer"
    inherit_cache = True

The above function will render as follows:

>>> print(func.geo.buffer())
ST_Buffer()

The name will be rendered as is, however without quoting unless the name contains special characters that require quoting. To force quoting on or off for the name, use the .sqlalchemy.sql.quoted_name construct:

from sqlalchemy.sql import quoted_name

class GeoBuffer(GenericFunction):
    type = Geometry
    package = "geo"
    name = quoted_name("ST_Buffer", True)
    identifier = "buffer"
    inherit_cache = True

The above function will render as:

>>> print(func.geo.buffer())
"ST_Buffer"()
New in version 1.3.13: The .quoted_name construct is now recognized for quoting when used with the "name" attribute of the object, so that quoting can be forced on or off for the function name.
Method __init__ Undocumented
Class Variable ​_register Undocumented
Class Variable coerce​_arguments Undocumented
Class Variable inherit​_cache Undocumented
Instance Variable ​_bind Undocumented
Instance Variable ​_has​_args Undocumented
Instance Variable clause​_expr Undocumented
Instance Variable packagenames Undocumented
Instance Variable type Undocumented
_register: bool =

Undocumented

coerce_arguments: bool =

Undocumented

_bind =

Undocumented

clause_expr =

Undocumented

packagenames: tuple =

Undocumented