SQL and Generic Functions
Note that any name not known to func
generates the function name as is - there is no restriction on what SQL functions can be called, known or unknown to SQLAlchemy, built-in or user defined. The section here only describes those functions where SQLAlchemy already knows what argument and return types are in use.
See also
Working with SQL Functions - in the
SQL function API, factories, and built-in functions.
class sqlalchemy.sql.functions.``AnsiFunction
(\args, **kwargs*)
Define a function in “ansi” format, which doesn’t render parenthesis.
Class signature
class sqlalchemy.sql.functions.AnsiFunction
()
class sqlalchemy.sql.functions.``Function
(name, \clauses, **kw*)
Describe a named SQL function.
The Function
object is typically generated from the generation object.
Parameters
*clauses – list of column expressions that form the arguments of the SQL function call.
type_ – optional
TypeEngine
datatype object that will be used as the return value of the column expression generated by this function call.packagenames –
a string which indicates package prefix names to be prepended to the function name when the SQL is generated. The generator creates these when it is called using dotted format, e.g.:
func.mypackage.some_function(col1, col2)
See also
Working with SQL Functions - in the
func
- namespace which produces registered or ad-hoc instances.
GenericFunction
- allows creation of registered function types.
Class signature
class (sqlalchemy.sql.functions.FunctionElement
)
method
__init__
(name, \clauses, **kw*)Construct a
Function
.The construct is normally used to construct new
Function
instances.attribute
type
= NullType()A
TypeEngine
object which refers to the SQL return type represented by this SQL function.This datatype may be configured when generating a object by passing the
Function.type_
parameter, e.g.:>>> select(func.lower("some VALUE", type_=String))
The small number of built-in classes of come with a built-in datatype that’s appropriate to the class of function and its arguments. For functions that aren’t known, the type defaults to the “null type”.
class sqlalchemy.sql.functions.``FunctionAsBinary
(fn, left_index, right_index)
Class signature
class sqlalchemy.sql.functions.FunctionAsBinary
()
class sqlalchemy.sql.functions.``FunctionElement
(\clauses, **kwargs*)
Base for SQL function-oriented constructs.
See also
Functions - in the Core tutorial
- named SQL function.
func
- namespace which produces registered or ad-hoc instances.
GenericFunction
- allows creation of registered function types.
Class signature
class (sqlalchemy.sql.expression.Executable
, , sqlalchemy.sql.expression.FromClause
, sqlalchemy.sql.expression.Generative
)
method
__init__
(\clauses, **kwargs*)Construct a
FunctionElement
.Parameters
*clauses – list of column expressions that form the arguments of the SQL function call.
**kwargs – additional kwargs are typically consumed by subclasses.
See also
[`func`]($f62ce11674ae62ed.md#sqlalchemy.sql.expression.func "sqlalchemy.sql.expression.func")
[`Function`](#sqlalchemy.sql.functions.Function "sqlalchemy.sql.functions.Function")
method
alias
(name=None)Produce a
Alias
construct against this .Tip
The
FunctionElement.alias()
method is part of the mechanism by which “table valued” SQL functions are created. However, most use cases are covered by higher level methods on includingFunctionElement.table_valued()
, and .This construct wraps the function in a named alias which is suitable for the FROM clause, in the style accepted for example by PostgreSQL. A column expression is also provided using the special
.column
attribute, which may be used to refer to the output of the function as a scalar value in the columns or where clause, for a backend such as PostgreSQL.For a full table-valued expression, use the
FunctionElement.table_valued()
method first to establish named columns.e.g.:
>>> from sqlalchemy import func, select, column
>>> data_view = func.unnest([1, 2, 3]).alias("data_view")
>>> print(select(data_view.column))
SELECT data_view
FROM unnest(:unnest_1) AS data_view
The
FunctionElement.column_valued()
method provides a shortcut for the above pattern:>>> data_view = func.unnest([1, 2, 3]).column_valued("data_view")
>>> print(select(data_view))
SELECT data_view
FROM unnest(:unnest_1) AS data_view
New in version 1.4.0b2: Added the
.column
accessorSee also
- in the SQLAlchemy 1.4 / 2.0 Tutorial
method
sqlalchemy.sql.functions.FunctionElement.
as_comparison
(left_index, right_index)Interpret this expression as a boolean comparison between two values.
This method is used for an ORM use case described at .
A hypothetical SQL function “is_equal()” which compares to values for equality would be written in the Core expression language as:
expr = func.is_equal("a", "b")
If “is_equal()” above is comparing “a” and “b” for equality, the
FunctionElement.as_comparison()
method would be invoked as:expr = func.is_equal("a", "b").as_comparison(1, 2)
Where above, the integer value “1” refers to the first argument of the “is_equal()” function and the integer value “2” refers to the second.
This would create a that is equivalent to:
BinaryExpression("a", "b", operator=op.eq)
However, at the SQL level it would still render as “is_equal(‘a’, ‘b’)”.
The ORM, when it loads a related object or collection, needs to be able to manipulate the “left” and “right” sides of the ON clause of a JOIN expression. The purpose of this method is to provide a SQL function construct that can also supply this information to the ORM, when used with the
relationship.primaryjoin
parameter. The return value is a containment object called .An ORM example is as follows:
class Venue(Base):
__tablename__ = 'venue'
id = Column(Integer, primary_key=True)
name = Column(String)
descendants = relationship(
"Venue",
primaryjoin=func.instr(
remote(foreign(name)), name + "/"
).as_comparison(1, 2) == 1,
viewonly=True,
order_by=name
)
Above, the “Venue” class can load descendant “Venue” objects by determining if the name of the parent Venue is contained within the start of the hypothetical descendant value’s name, e.g. “parent1” would match up to “parent1/child1”, but not to “parent2/child1”.
Possible use cases include the “materialized path” example given above, as well as making use of special SQL functions such as geometric functions to create join conditions.
Parameters
left_index – the integer 1-based index of the function argument that serves as the “left” side of the expression.
New in version 1.3.
See also
[Custom operators based on SQL functions]($e1f42b7742e49253.md#relationship-custom-operator-sql-function) - example use within the ORM
attribute
sqlalchemy.sql.functions.FunctionElement.
clauses
Return the underlying which contains the arguments for this
FunctionElement
.method
column_valued
(name=None)Return this
FunctionElement
as a column expression that selects from itself as a FROM clause.E.g.:
>>> from sqlalchemy import select, func
>>> gs = func.generate_series(1, 5, -1).column_valued()
>>> print(select(gs))
SELECT anon_1
FROM generate_series(:generate_series_1, :generate_series_2, :generate_series_3) AS anon_1
This is shorthand for:
gs = func.generate_series(1, 5, -1).alias().column
See also
- in the SQLAlchemy 1.4 / 2.0 Tutorial
- in the PostgreSQL documentation
attribute
sqlalchemy.sql.functions.FunctionElement.
columns
The set of columns exported by this .
This is a placeholder collection that allows the function to be placed in the FROM clause of a statement:
The above form is a legacy feature that is now superseded by the fully capable
FunctionElement.table_valued()
method; see that method for details.See also
- generates table-valued SQL function expressions.
method
sqlalchemy.sql.functions.FunctionElement.
execute
()Execute this against an embedded ‘bind’.
Deprecated since version 1.4: The
FunctionElement.execute()
method is considered legacy as of the 1.x series of SQLAlchemy and will be removed in 2.0. All statement execution in SQLAlchemy 2.0 is performed by the method ofConnection
, or in the ORM by the method ofSession
. (Background on SQLAlchemy 2.0 at: )This first calls
FunctionElement.select()
to produce a SELECT construct.Note that can be passed to the
Connectable.execute()
method ofConnection
or .method
sqlalchemy.sql.functions.FunctionElement.
over
(partition_by=None, order_by=None, rows=None, range_=None)Produce an OVER clause against this function.
Used against aggregate or so-called “window” functions, for database backends that support window functions.
The expression:
func.row_number().over(order_by='x')
is shorthand for:
from sqlalchemy import over
over(func.row_number(), order_by='x')
See for a full description.
See also
- in the SQLAlchemy 1.4 / 2.0 Tutorial
method
scalar
()Execute this
FunctionElement
against an embedded ‘bind’ and return a scalar value.Deprecated since version 1.4: The method is considered legacy as of the 1.x series of SQLAlchemy and will be removed in 2.0. Scalar execution in SQLAlchemy 2.0 is performed by the
Connection.scalar()
method of , or in the ORM by theSession.scalar()
method of . (Background on SQLAlchemy 2.0 at: Migrating to SQLAlchemy 2.0)This first calls to produce a SELECT construct.
Note that
FunctionElement
can be passed to theConnectable.scalar()
method of orEngine
.method
scalar_table_valued
(name, type_=None)Return a column expression that’s against this
FunctionElement
as a scalar table-valued expression.The returned expression is similar to that returned by a single column accessed off of a construct, except no FROM clause is generated; the function is rendered in the similar way as a scalar subquery.
E.g.:
>>> from sqlalchemy import func, select
>>> fn = func.jsonb_each("{'k', 'v'}").scalar_table_valued("key")
>>> print(select(fn))
SELECT (jsonb_each(:jsonb_each_1)).key
New in version 1.4.0b2.
See also
method
select
()Produce a
select()
construct against this .This is shorthand for:
s = select(function_element)
method
sqlalchemy.sql.functions.FunctionElement.
self_group
(against=None)Apply a ‘grouping’ to this .
This method is overridden by subclasses to return a “grouping” construct, i.e. parenthesis. In particular it’s used by “binary” expressions to provide a grouping around themselves when placed into a larger expression, as well as by
select()
constructs when placed into the FROM clause of another . (Note that subqueries should be normally created using theSelect.alias()
method, as many platforms require nested SELECT statements to be named).As expressions are composed together, the application of is automatic - end-user code should never need to use this method directly. Note that SQLAlchemy’s clause constructs take operator precedence into account - so parenthesis might not be needed, for example, in an expression like
x OR (y AND z)
- AND takes precedence over OR.The base
self_group()
method of just returns self.method
sqlalchemy.sql.functions.FunctionElement.
table_valued
(\expr, **kw*)Return a representation of this
FunctionElement
with table-valued expressions added.e.g.:
>>> fn = (
... func.generate_series(1, 5).
... table_valued("value", "start", "stop", "step")
... )
>>> print(select(fn))
SELECT anon_1.value, anon_1.start, anon_1.stop, anon_1.step
FROM generate_series(:generate_series_1, :generate_series_2) AS anon_1
>>> print(select(fn.c.value, fn.c.stop).where(fn.c.value > 2))
SELECT anon_1.value, anon_1.stop
FROM generate_series(:generate_series_1, :generate_series_2) AS anon_1
WHERE anon_1.value > :value_1
A WITH ORDINALITY expression may be generated by passing the keyword argument “with_ordinality”:
>>> fn = func.generate_series(4, 1, -1).table_valued("gen", with_ordinality="ordinality")
>>> print(select(fn))
SELECT anon_1.gen, anon_1.ordinality
FROM generate_series(:generate_series_1, :generate_series_2, :generate_series_3) WITH ORDINALITY AS anon_1
Parameters
*expr – A series of string column names that will be added to the
.c
collection of the resulting construct as columns.column()
objects with or without datatypes may also be used.name – optional name to assign to the alias name that’s generated. If omitted, a unique anonymizing name is used.
with_ordinality – string name that when present results in the
WITH ORDINALITY
clause being added to the alias, and the given string name will be added as a column to the .c collection of the resulting .
New in version 1.4.0b2.
See also
[Table-Valued Functions]($cfdc81b69abe0678.md#tutorial-functions-table-valued) - in the [SQLAlchemy 1.4 / 2.0 Tutorial]($2006f9816d864d8d.md#unified-tutorial)
[Table-Valued Functions]($d951abc5c7ad81e4.md#postgresql-table-valued) - in the [PostgreSQL]($d951abc5c7ad81e4.md) documentation
[`FunctionElement.scalar_table_valued()`](#sqlalchemy.sql.functions.FunctionElement.scalar_table_valued "sqlalchemy.sql.functions.FunctionElement.scalar_table_valued") - variant of [`FunctionElement.table_valued()`](#sqlalchemy.sql.functions.FunctionElement.table_valued "sqlalchemy.sql.functions.FunctionElement.table_valued") which delivers the complete table valued expression as a scalar column expression
[`FunctionElement.column_valued()`](#sqlalchemy.sql.functions.FunctionElement.column_valued "sqlalchemy.sql.functions.FunctionElement.column_valued")
[`TableValuedAlias.render_derived()`]($fc2d211e9d1454ca.md#sqlalchemy.sql.expression.TableValuedAlias.render_derived "sqlalchemy.sql.expression.TableValuedAlias.render_derived") - renders the alias using a derived column clause, e.g. `AS name(col1, col2, ...)`
method
sqlalchemy.sql.functions.FunctionElement.
within_group
(\order_by*)Produce a WITHIN GROUP (ORDER BY expr) clause against this function.
Used against so-called “ordered set aggregate” and “hypothetical set aggregate” functions, including ,
rank
, , etc.See
within_group()
for a full description.New in version 1.1.
See also
- in the SQLAlchemy 1.4 / 2.0 Tutorial
method
within_group_type
(within_group)For types that define their return type as based on the criteria within a WITHIN GROUP (ORDER BY) expression, called by the
WithinGroup
construct.Returns None by default, in which case the function’s normal
.type
is used.
class sqlalchemy.sql.functions.``GenericFunction
(\args, **kwargs*)
Define a ‘generic’ function.
A generic function is a pre-established class that is instantiated automatically when called by name from the func
attribute. Note that calling any name from has the effect that a new Function
instance is created automatically, given that name. The primary use case for defining a 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
print(select(func.as_utc()))
User-defined generic functions can be organized into packages by specifying the “package” attribute when defining . 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
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 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:
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 quoted_name
construct:
from sqlalchemy.sql import quoted_name
class GeoBuffer(GenericFunction):
type = Geometry
package = "geo"
name = quoted_name("ST_Buffer", True)
identifier = "buffer"
The above function will render as:
>>> print(func.geo.buffer())
"ST_Buffer"()
New in version 1.3.13: The 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.
Class signature
class sqlalchemy.sql.functions.GenericFunction
()
class sqlalchemy.sql.functions.``OrderedSetAgg
(\args, **kwargs*)
Define a function where the return type is based on the sort expression type as defined by the expression passed to the FunctionElement.within_group()
method.
Class signature
class (sqlalchemy.sql.functions.GenericFunction
)
method
within_group_type
(within_group)For types that define their return type as based on the criteria within a WITHIN GROUP (ORDER BY) expression, called by the
WithinGroup
construct.Returns None by default, in which case the function’s normal
.type
is used.
class sqlalchemy.sql.functions.``ReturnTypeFromArgs
(\args, **kwargs*)
Define a function whose return type is the same as its arguments.
Class signature
class (sqlalchemy.sql.functions.GenericFunction
)
class sqlalchemy.sql.functions.``ScalarFunctionColumn
(fn, name, type_=None)
Class signature
class (sqlalchemy.sql.expression.NamedColumn
)
class sqlalchemy.sql.functions.``array_agg
(\args, **kwargs*)
Support for the ARRAY_AGG function.
The func.array_agg(expr)
construct returns an expression of type ARRAY
.
e.g.:
stmt = select(func.array_agg(table.c.values)[2:5])
New in version 1.1.
See also
- PostgreSQL-specific version that returns ARRAY
, which has PG-specific operators added.
Class signature
class (sqlalchemy.sql.functions.GenericFunction
)
attribute
type
alias of
sqlalchemy.sql.sqltypes.ARRAY
class sqlalchemy.sql.functions.``char_length
(arg, \*kwargs*)
The CHAR_LENGTH() SQL function.
Class signature
class sqlalchemy.sql.functions.char_length
()
attribute
sqlalchemy.sql.functions.char_length.
type
alias of
sqlalchemy.sql.sqltypes.Integer
class sqlalchemy.sql.functions.``coalesce
(\args, **kwargs*)
Class signature
class (sqlalchemy.sql.functions.ReturnTypeFromArgs
)
class sqlalchemy.sql.functions.``concat
(\args, **kwargs*)
The SQL CONCAT() function, which concatenates strings.
E.g.:
>>> print(select(func.concat('a', 'b')))
SELECT concat(:concat_2, :concat_3) AS concat_1
String concatenation in SQLAlchemy is more commonly available using the Python +
operator with string datatypes, which will render a backend-specific concatenation operator, such as
>>> print(select(literal("a") + "b"))
Class signature
class (sqlalchemy.sql.functions.GenericFunction
)
attribute
type
alias of
sqlalchemy.sql.sqltypes.String
class sqlalchemy.sql.functions.``count
(expression=None, \*kwargs*)
The ANSI COUNT aggregate function. With no arguments, emits COUNT *.
E.g.:
from sqlalchemy import func
from sqlalchemy import select
from sqlalchemy import table, column
my_table = table('some_table', column('id'))
stmt = select(func.count()).select_from(my_table)
Executing stmt
would emit:
SELECT count(*) AS count_1
FROM some_table
Class signature
class sqlalchemy.sql.functions.count
()
attribute
sqlalchemy.sql.functions.count.
type
alias of
sqlalchemy.sql.sqltypes.Integer
class sqlalchemy.sql.functions.``cube
(\args, **kwargs*)
Implement the CUBE
grouping operation.
This function is used as part of the GROUP BY of a statement, e.g. :
stmt = select(
func.sum(table.c.value), table.c.col_1, table.c.col_2
).group_by(func.cube(table.c.col_1, table.c.col_2))
New in version 1.2.
Class signature
class sqlalchemy.sql.functions.cube
()
Implement the cume_dist
hypothetical-set aggregate function.
This function must be used with the FunctionElement.within_group()
modifier to supply a sort expression to operate upon.
The return type of this function is .
New in version 1.1.
Class signature
class sqlalchemy.sql.functions.cume_dist
()
class sqlalchemy.sql.functions.``current_date
(\args, **kwargs*)
The CURRENT_DATE() SQL function.
Class signature
class sqlalchemy.sql.functions.current_date
()
attribute
sqlalchemy.sql.functions.current_date.
type
alias of
sqlalchemy.sql.sqltypes.Date
class sqlalchemy.sql.functions.``current_time
(\args, **kwargs*)
The CURRENT_TIME() SQL function.
Class signature
class (sqlalchemy.sql.functions.AnsiFunction
)
attribute
type
alias of
sqlalchemy.sql.sqltypes.Time
class sqlalchemy.sql.functions.``current_timestamp
(\args, **kwargs*)
The CURRENT_TIMESTAMP() SQL function.
Class signature
class sqlalchemy.sql.functions.current_timestamp
()
attribute
sqlalchemy.sql.functions.current_timestamp.
type
alias of
sqlalchemy.sql.sqltypes.DateTime
class sqlalchemy.sql.functions.``current_user
(\args, **kwargs*)
The CURRENT_USER() SQL function.
Class signature
class (sqlalchemy.sql.functions.AnsiFunction
)
attribute
type
alias of
sqlalchemy.sql.sqltypes.String
class sqlalchemy.sql.functions.``dense_rank
(\args, **kwargs*)
Implement the dense_rank
hypothetical-set aggregate function.
This function must be used with the FunctionElement.within_group()
modifier to supply a sort expression to operate upon.
The return type of this function is .
New in version 1.1.
Class signature
class sqlalchemy.sql.functions.dense_rank
()
class sqlalchemy.sql.functions.``grouping_sets
(\args, **kwargs*)
Implement the GROUPING SETS
grouping operation.
This function is used as part of the GROUP BY of a statement, e.g. Select.group_by()
:
stmt = select(
func.sum(table.c.value), table.c.col_1, table.c.col_2
).group_by(func.grouping_sets(table.c.col_1, table.c.col_2))
In order to group by multiple sets, use the construct:
from sqlalchemy import tuple_
stmt = select(
func.sum(table.c.value),
table.c.col_1, table.c.col_2,
table.c.col_3
).group_by(
func.grouping_sets(
tuple_(table.c.col_1, table.c.col_2),
tuple_(table.c.value, table.c.col_3),
)
)
New in version 1.2.
Class signature
class sqlalchemy.sql.functions.grouping_sets
()
class sqlalchemy.sql.functions.``localtime
(\args, **kwargs*)
The localtime() SQL function.
Class signature
class sqlalchemy.sql.functions.localtime
()
attribute
sqlalchemy.sql.functions.localtime.
type
alias of
sqlalchemy.sql.sqltypes.DateTime
class sqlalchemy.sql.functions.``localtimestamp
(\args, **kwargs*)
The localtimestamp() SQL function.
Class signature
class (sqlalchemy.sql.functions.AnsiFunction
)
attribute
type
alias of
sqlalchemy.sql.sqltypes.DateTime
class sqlalchemy.sql.functions.``max
(\args, **kwargs*)
The SQL MAX() aggregate function.
Class signature
class sqlalchemy.sql.functions.max
()
class sqlalchemy.sql.functions.``min
(\args, **kwargs*)
The SQL MIN() aggregate function.
Class signature
class sqlalchemy.sql.functions.min
()
class sqlalchemy.sql.functions.``mode
(\args, **kwargs*)
Implement the mode
ordered-set aggregate function.
This function must be used with the FunctionElement.within_group()
modifier to supply a sort expression to operate upon.
The return type of this function is the same as the sort expression.
New in version 1.1.
Class signature
class (sqlalchemy.sql.functions.OrderedSetAgg
)
class sqlalchemy.sql.functions.``next_value
(seq, \*kw*)
Represent the ‘next value’, given a as its single argument.
Compiles into the appropriate function on each backend, or will raise NotImplementedError if used on a backend that does not provide support for sequences.
Class signature
class sqlalchemy.sql.functions.next_value
()
method
sqlalchemy.sql.functions.next_value.
compare
(other, \*kw*)Compare this to the given
ClauseElement
.Subclasses should override the default behavior, which is a straight identity comparison.
**kw are arguments consumed by subclass
compare()
methods and may be used to modify the criteria for comparison (see ).
class sqlalchemy.sql.functions.``now
(\args, **kwargs*)
The SQL now() datetime function.
SQLAlchemy dialects will usually render this particular function in a backend-specific way, such as rendering it as CURRENT_TIMESTAMP
.
Class signature
class sqlalchemy.sql.functions.now
()
attribute
sqlalchemy.sql.functions.now.
type
alias of
sqlalchemy.sql.sqltypes.DateTime
class sqlalchemy.sql.functions.``percent_rank
(\args, **kwargs*)
Implement the percent_rank
hypothetical-set aggregate function.
This function must be used with the modifier to supply a sort expression to operate upon.
The return type of this function is Numeric
.
New in version 1.1.
Class signature
class (sqlalchemy.sql.functions.GenericFunction
)
class sqlalchemy.sql.functions.``percentile_cont
(\args, **kwargs*)
Implement the percentile_cont
ordered-set aggregate function.
This function must be used with the modifier to supply a sort expression to operate upon.
The return type of this function is the same as the sort expression, or if the arguments are an array, an ARRAY
of the sort expression’s type.
New in version 1.1.
Class signature
class (sqlalchemy.sql.functions.OrderedSetAgg
)
class sqlalchemy.sql.functions.``percentile_disc
(\args, **kwargs*)
Implement the percentile_disc
ordered-set aggregate function.
This function must be used with the modifier to supply a sort expression to operate upon.
The return type of this function is the same as the sort expression, or if the arguments are an array, an ARRAY
of the sort expression’s type.
New in version 1.1.
Class signature
class (sqlalchemy.sql.functions.OrderedSetAgg
)
class sqlalchemy.sql.functions.``random
(\args, **kwargs*)
The RANDOM() SQL function.
Class signature
class (sqlalchemy.sql.functions.GenericFunction
)
class sqlalchemy.sql.functions.``rank
(\args, **kwargs*)
Implement the rank
hypothetical-set aggregate function.
This function must be used with the modifier to supply a sort expression to operate upon.
The return type of this function is Integer
.
New in version 1.1.
Class signature
class (sqlalchemy.sql.functions.GenericFunction
)
function sqlalchemy.sql.functions.``register_function
(identifier, fn, package=’_default’)
Associate a callable with a particular func. name.
This is normally called by _GenericMeta, but is also available by itself so that a non-Function construct can be associated with the accessor (i.e. CAST, EXTRACT).
class sqlalchemy.sql.functions.``rollup
(\args, **kwargs*)
Implement the ROLLUP
grouping operation.
This function is used as part of the GROUP BY of a statement, e.g. Select.group_by()
:
stmt = select(
func.sum(table.c.value), table.c.col_1, table.c.col_2
).group_by(func.rollup(table.c.col_1, table.c.col_2))
New in version 1.2.
Class signature
class (sqlalchemy.sql.functions.GenericFunction
)
class sqlalchemy.sql.functions.``session_user
(\args, **kwargs*)
The SESSION_USER() SQL function.
Class signature
class (sqlalchemy.sql.functions.AnsiFunction
)
attribute
type
alias of
sqlalchemy.sql.sqltypes.String
class sqlalchemy.sql.functions.``sum
(\args, **kwargs*)
The SQL SUM() aggregate function.
Class signature
class sqlalchemy.sql.functions.sum
()
class sqlalchemy.sql.functions.``sysdate
(\args, **kwargs*)
The SYSDATE() SQL function.
Class signature
class sqlalchemy.sql.functions.sysdate
()
attribute
sqlalchemy.sql.functions.sysdate.
type
alias of
sqlalchemy.sql.sqltypes.DateTime
class sqlalchemy.sql.functions.``user
(\args, **kwargs*)
The USER() SQL function.
Class signature
class (sqlalchemy.sql.functions.AnsiFunction
)