SQLAlchemy 0.6 Documentation

Release: 0.6.9 | Release Date: May 5, 2012
SQLAlchemy 0.6 Documentation » SQLAlchemy Core » SQL Statements and Expressions

SQL Statements and Expressions

SQL Statements and Expressions

This section presents the API reference for the SQL Expression Language. For a full introduction to its usage, see SQL Expression Language Tutorial.

Functions

The expression package uses functions to construct SQL expressions. The return value of each function is an object instance which is a subclass of ClauseElement.

sqlalchemy.sql.expression.alias(selectable, alias=None)

Return an Alias object.

An Alias represents any FromClause with an alternate name assigned within SQL, typically using the AS clause when generated, e.g. SELECT * FROM table AS aliasname.

Similar functionality is available via the alias() method available on all FromClause subclasses.

When an Alias is created from a Table object, this has the effect of the table being rendered as tablename AS aliasname in a SELECT statement.

For select() objects, the effect is that of creating a named subquery, i.e. (select ...) AS aliasname.

The alias parameter is optional, and provides the name to use in the rendered SQL. If blank, an “anonymous” name will be deterministically generated at compile time. Deterministic means the name is guaranteed to be unique against other constructs used in the same statement, and will also be the same name for each successive compilation of the same statement object.

Parameters:
  • selectable – any FromClause subclass, such as a table, select statement, etc.
  • alias – string name to be assigned as the alias. If None, a name will be deterministically generated at compile time. Deprecated - this argument is called name in 0.7 for consistency with the other aliasing methods.
sqlalchemy.sql.expression.and_(*clauses)

Join a list of clauses together using the AND operator.

The & operator is also overloaded on all _CompareMixin subclasses to produce the same result.

sqlalchemy.sql.expression.asc(column)

Return an ascending ORDER BY clause element.

e.g.:

order_by = [asc(table1.mycol)]
sqlalchemy.sql.expression.between(ctest, cleft, cright)

Return a BETWEEN predicate clause.

Equivalent of SQL clausetest BETWEEN clauseleft AND clauseright.

The between() method on all _CompareMixin subclasses provides similar functionality.

sqlalchemy.sql.expression.bindparam(key, value=None, type_=None, unique=False, required=False)

Create a bind parameter clause with the given key.

value
a default value for this bind parameter. a bindparam with a value is called a value-based bindparam.
type_
a sqlalchemy.types.TypeEngine object indicating the type of this bind param, will invoke type-specific bind parameter processing
unique
if True, bind params sharing the same name will have their underlying key modified to a uniquely generated name. mostly useful with value-based bind params.
required
A value is required at execution time.
sqlalchemy.sql.expression.case(whens, value=None, else_=None)

Produce a CASE statement.

whens
A sequence of pairs, or alternatively a dict, to be translated into “WHEN / THEN” clauses.
value
Optional for simple case statements, produces a column expression as in “CASE <expr> WHEN ...”
else_
Optional as well, for case defaults produces the “ELSE” portion of the “CASE” statement.

The expressions used for THEN and ELSE, when specified as strings, will be interpreted as bound values. To specify textual SQL expressions for these, use the literal_column() construct.

The expressions used for the WHEN criterion may only be literal strings when “value” is present, i.e. CASE table.somecol WHEN “x” THEN “y”. Otherwise, literal strings are not accepted in this position, and either the text(<string>) or literal(<string>) constructs must be used to interpret raw string values.

Usage examples:

case([(orderline.c.qty > 100, item.c.specialprice),
      (orderline.c.qty > 10, item.c.bulkprice)
    ], else_=item.c.regularprice)
case(value=emp.c.type, whens={
        'engineer': emp.c.salary * 1.1,
        'manager':  emp.c.salary * 3,
    })

Using literal_column(), to allow for databases that do not support bind parameters in the then clause. The type can be specified which determines the type of the case() construct overall:

case([(orderline.c.qty > 100, 
        literal_column("'greaterthan100'", String)),
      (orderline.c.qty > 10, literal_column("'greaterthan10'",
        String))
    ], else_=literal_column("'lethan10'", String))
sqlalchemy.sql.expression.cast(clause, totype, **kwargs)

Return a CAST function.

Equivalent of SQL CAST(clause AS totype).

Use with a TypeEngine subclass, i.e:

cast(table.c.unit_price * table.c.qty, Numeric(10,4))

or:

cast(table.c.timestamp, DATE)
sqlalchemy.sql.expression.column(text, type_=None)

Return a textual column clause, as would be in the columns clause of a SELECT statement.

The object returned is an instance of ColumnClause, which represents the “syntactical” portion of the schema-level Column object. It is often used directly within select() constructs or with lightweight table() constructs.

Note that the column() function is not part of the sqlalchemy namespace. It must be imported from the sql package:

from sqlalchemy.sql import table, column
Parameters:
  • text – the name of the column. Quoting rules will be applied to the clause like any other column name. For textual column constructs that are not to be quoted, use the literal_column() function.
  • type_ – an optional TypeEngine object which will provide result-set translation for this column.

See ColumnClause for further examples.

sqlalchemy.sql.expression.collate(expression, collation)

Return the clause expression COLLATE collation.

sqlalchemy.sql.expression.delete(table, whereclause=None, **kwargs)

Return a Delete clause element.

Similar functionality is available via the delete() method on Table.

Parameters:
  • table – The table to be updated.
  • whereclause – A ClauseElement describing the WHERE condition of the UPDATE statement. Note that the where() generative method may be used instead.
sqlalchemy.sql.expression.desc(column)

Return a descending ORDER BY clause element.

e.g.:

order_by = [desc(table1.mycol)]
sqlalchemy.sql.expression.distinct(expr)

Return a DISTINCT clause.

sqlalchemy.sql.expression.except_(*selects, **kwargs)

Return an EXCEPT of multiple selectables.

The returned object is an instance of CompoundSelect.

*selects
a list of Select instances.
**kwargs
available keyword arguments are the same as those of select().
sqlalchemy.sql.expression.except_all(*selects, **kwargs)

Return an EXCEPT ALL of multiple selectables.

The returned object is an instance of CompoundSelect.

*selects
a list of Select instances.
**kwargs
available keyword arguments are the same as those of select().
sqlalchemy.sql.expression.exists(*args, **kwargs)

Return an EXISTS clause as applied to a Select object.

Calling styles are of the following forms:

# use on an existing select()
s = select([table.c.col1]).where(table.c.col2==5)
s = exists(s)

# construct a select() at once
exists(['*'], **select_arguments).where(criterion)

# columns argument is optional, generates "EXISTS (SELECT *)"
# by default.
exists().where(table.c.col2==5)
sqlalchemy.sql.expression.extract(field, expr)

Return the clause extract(field FROM expr).

sqlalchemy.sql.expression.func = <sqlalchemy.sql.expression._FunctionGenerator object at 0x2b36f6f41210>

Generate SQL function expressions.

func is a special object instance which generates SQL functions based on name-based attributes, e.g.:

>>> print func.count(1)
count(:param_1)

Any name can be given to 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:

>>> print func.current_timestamp()
CURRENT_TIMESTAMP

To call functions which are present in dot-separated packages, specify them in the same manner:

>>> print func.stats.yield_curve(5, 10)
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 Unicode as the type:

>>> print func.my_string(u'hi', type_=Unicode) + ' ' + \
... func.my_string(u'there', type_=Unicode)
my_string(:my_string_1) || :my_string_2 || my_string(:my_string_3)

Functions which are interpreted as “generic” functions know how to calculate their return type automatically. For a listing of known generic functions, see Generic Functions.

sqlalchemy.sql.expression.insert(table, values=None, inline=False, **kwargs)

Return an Insert clause element.

Similar functionality is available via the insert() method on Table.

Parameters:
  • table – The table to be inserted into.
  • values – A dictionary which specifies the column specifications of the INSERT, and is optional. If left as None, the column specifications are determined from the bind parameters used during the compile phase of the INSERT statement. If the bind parameters also are None during the compile phase, then the column specifications will be generated from the full list of table columns. Note that the values() generative method may also be used for this.
  • prefixes – A list of modifier keywords to be inserted between INSERT and INTO. Alternatively, the prefix_with() generative method may be used.
  • inline – if True, SQL defaults will be compiled ‘inline’ into the statement and not pre-executed.

If both values and compile-time bind parameters are present, the compile-time bind parameters override the information specified within values on a per-key basis.

The keys within values can be either Column objects or their string identifiers. Each key may reference one of:

  • a literal data value (i.e. string, number, etc.);
  • a Column object;
  • a SELECT statement.

If a SELECT statement is specified which references this INSERT statement’s table, the statement will be correlated against the INSERT statement.

sqlalchemy.sql.expression.intersect(*selects, **kwargs)

Return an INTERSECT of multiple selectables.

The returned object is an instance of CompoundSelect.

*selects
a list of Select instances.
**kwargs
available keyword arguments are the same as those of select().
sqlalchemy.sql.expression.intersect_all(*selects, **kwargs)

Return an INTERSECT ALL of multiple selectables.

The returned object is an instance of CompoundSelect.

*selects
a list of Select instances.
**kwargs
available keyword arguments are the same as those of select().
sqlalchemy.sql.expression.join(left, right, onclause=None, isouter=False)

Return a JOIN clause element (regular inner join).

The returned object is an instance of Join.

Similar functionality is also available via the join() method on any FromClause.

left
The left side of the join.
right
The right side of the join.
onclause
Optional criterion for the ON clause, is derived from foreign key relationships established between left and right otherwise.

To chain joins together, use the join() or outerjoin() methods on the resulting Join object.

sqlalchemy.sql.expression.label(name, obj)

Return a _Label object for the given ColumnElement.

A label changes the name of an element in the columns clause of a SELECT statement, typically via the AS SQL keyword.

This functionality is more conveniently available via the label() method on ColumnElement.

name
label name
obj
a ColumnElement.
sqlalchemy.sql.expression.literal(value, type_=None)

Return a literal clause, bound to a bind parameter.

Literal clauses are created automatically when non- ClauseElement objects (such as strings, ints, dates, etc.) are used in a comparison operation with a _CompareMixin subclass, such as a Column object. Use this function to force the generation of a literal clause, which will be created as a _BindParamClause with a bound value.

Parameters:
  • value – the value to be bound. Can be any Python object supported by the underlying DB-API, or is translatable via the given type argument.
  • type_ – an optional TypeEngine which will provide bind-parameter translation for this literal.
sqlalchemy.sql.expression.literal_column(text, type_=None)

Return a textual column expression, as would be in the columns clause of a SELECT statement.

The object returned supports further expressions in the same way as any other column object, including comparison, math and string operations. The type_ parameter is important to determine proper expression behavior (such as, ‘+’ means string concatenation or numerical addition based on the type).

Parameters:
  • text – the text of the expression; can be any SQL expression. Quoting rules will not be applied. To specify a column-name expression which should be subject to quoting rules, use the column() function.
  • type_ – an optional TypeEngine object which will provide result-set translation and additional expression semantics for this column. If left as None the type will be NullType.
sqlalchemy.sql.expression.not_(clause)

Return a negation of the given clause, i.e. NOT(clause).

The ~ operator is also overloaded on all _CompareMixin subclasses to produce the same result.

sqlalchemy.sql.expression.null()

Return a _Null object, which compiles to NULL in a sql statement.

sqlalchemy.sql.expression.or_(*clauses)

Join a list of clauses together using the OR operator.

The | operator is also overloaded on all _CompareMixin subclasses to produce the same result.

sqlalchemy.sql.expression.outparam(key, type_=None)

Create an ‘OUT’ parameter for usage in functions (stored procedures), for databases which support them.

The outparam can be used like a regular function parameter. The “output” value will be available from the ResultProxy object via its out_parameters attribute, which returns a dictionary containing the values.

sqlalchemy.sql.expression.outerjoin(left, right, onclause=None)

Return an OUTER JOIN clause element.

The returned object is an instance of Join.

Similar functionality is also available via the outerjoin() method on any FromClause.

left
The left side of the join.
right
The right side of the join.
onclause
Optional criterion for the ON clause, is derived from foreign key relationships established between left and right otherwise.

To chain joins together, use the join() or outerjoin() methods on the resulting Join object.

sqlalchemy.sql.expression.select(columns=None, whereclause=None, from_obj=[], **kwargs)

Returns a SELECT clause element.

Similar functionality is also available via the select() method on any FromClause.

The returned object is an instance of Select.

All arguments which accept ClauseElement arguments also accept string arguments, which will be converted as appropriate into either text() or literal_column() constructs.

Parameters:
  • columns

    A list of ClauseElement objects, typically ColumnElement objects or subclasses, which will form the columns clause of the resulting statement. For all members which are instances of Selectable, the individual ColumnElement members of the Selectable will be added individually to the columns clause. For example, specifying a Table instance will result in all the contained Column objects within to be added to the columns clause.

    This argument is not present on the form of select() available on Table.

  • whereclause – A ClauseElement expression which will be used to form the WHERE clause.
  • from_obj – A list of ClauseElement objects which will be added to the FROM clause of the resulting statement. Note that “from” objects are automatically located within the columns and whereclause ClauseElements. Use this parameter to explicitly specify “from” objects which are not automatically locatable. This could include Table objects that aren’t otherwise present, or Join objects whose presence will supercede that of the Table objects already located in the other clauses.
  • autocommit – Deprecated. Use .execution_options(autocommit=<True|False>) to set the autocommit option.
  • prefixes – a list of strings or ClauseElement objects to include directly after the SELECT keyword in the generated statement, for dialect-specific query features.
  • distinct=False – when True, applies a DISTINCT qualifier to the columns clause of the resulting statement.
  • use_labels=False – when True, the statement will be generated using labels for each column in the columns clause, which qualify each column with its parent table’s (or aliases) name so that name conflicts between columns in different tables don’t occur. The format of the label is <tablename>_<column>. The “c” collection of the resulting Select object will use these names as well for targeting column members.
  • for_update=False – when True, applies FOR UPDATE to the end of the resulting statement. Certain database dialects also support alternate values for this parameter, for example mysql supports “read” which translates to LOCK IN SHARE MODE, and oracle supports “nowait” which translates to FOR UPDATE NOWAIT.
  • correlate=True – indicates that this Select object should have its contained FromClause elements “correlated” to an enclosing Select object. This means that any ClauseElement instance within the “froms” collection of this Select which is also present in the “froms” collection of an enclosing select will not be rendered in the FROM clause of this select statement.
  • group_by – a list of ClauseElement objects which will comprise the GROUP BY clause of the resulting select.
  • having – a ClauseElement that will comprise the HAVING clause of the resulting select when GROUP BY is used.
  • order_by – a scalar or list of ClauseElement objects which will comprise the ORDER BY clause of the resulting select.
  • limit=None – a numerical value which usually compiles to a LIMIT expression in the resulting select. Databases that don’t support LIMIT will attempt to provide similar functionality.
  • offset=None – a numeric value which usually compiles to an OFFSET expression in the resulting select. Databases that don’t support OFFSET will attempt to provide similar functionality.
  • bind=None – an Engine or Connection instance to which the resulting Select ` object will be bound.  The ``Select object will otherwise automatically bind to whatever Connectable instances can be located within its contained ClauseElement members.
sqlalchemy.sql.expression.subquery(alias, *args, **kwargs)

Return an Alias object derived from a Select.

name
alias name

*args, **kwargs

all other arguments are delivered to the select() function.
sqlalchemy.sql.expression.table(name, *columns)

Represent a textual table clause.

The object returned is an instance of TableClause, which represents the “syntactical” portion of the schema-level Table object. It may be used to construct lightweight table constructs.

Note that the table() function is not part of the sqlalchemy namespace. It must be imported from the sql package:

from sqlalchemy.sql import table, column
Parameters:
  • name – Name of the table.
  • columns – A collection of column() constructs.

See TableClause for further examples.

sqlalchemy.sql.expression.text(text, bind=None, *args, **kwargs)

Create a SQL construct that is represented by a literal string.

E.g.:

t = text("SELECT * FROM users")
result = connection.execute(t)

The advantages text() provides over a plain string are backend-neutral support for bind parameters, per-statement execution options, as well as bind parameter and result-column typing behavior, allowing SQLAlchemy type constructs to play a role when executing a statement that is specified literally.

Bind parameters are specified by name, using the format :name. E.g.:

t = text("SELECT * FROM users WHERE id=:user_id")
result = connection.execute(t, user_id=12)

To invoke SQLAlchemy typing logic for bind parameters, the bindparams list allows specification of bindparam() constructs which specify the type for a given name:

t = text("SELECT id FROM users WHERE updated_at>:updated",
            bindparams=[bindparam('updated', DateTime())]
        )

Typing during result row processing is also an important concern. Result column types are specified using the typemap dictionary, where the keys match the names of columns. These names are taken from what the DBAPI returns as cursor.description:

t = text("SELECT id, name FROM users",
        typemap={
            'id':Integer,
            'name':Unicode
        }
)

The text() construct is used internally for most cases when a literal string is specified for part of a larger query, such as within select(), update(), insert() or delete(). In those cases, the same bind parameter syntax is applied:

s = select([users.c.id, users.c.name]).where("id=:user_id")
result = connection.execute(s, user_id=12)

Using text() explicitly usually implies the construction of a full, standalone statement. As such, SQLAlchemy refers to it as an Executable object, and it supports the Executable.execution_options() method. For example, a text() construct that should be subject to “autocommit” can be set explicitly so using the autocommit option:

t = text("EXEC my_procedural_thing()").\
        execution_options(autocommit=True)

Note that SQLAlchemy’s usual “autocommit” behavior applies to text() constructs - that is, statements which begin with a phrase such as INSERT, UPDATE, DELETE, or a variety of other phrases specific to certain backends, will be eligible for autocommit if no transaction is in progress.

Parameters:
  • text – the text of the SQL statement to be created. use :<param> to specify bind parameters; they will be compiled to their engine-specific format.
  • autocommit – Deprecated. Use .execution_options(autocommit=<True|False>) to set the autocommit option.
  • bind – an optional connection or engine to be used for this text query.
  • bindparams – a list of bindparam() instances which can be used to define the types and/or initial values for the bind parameters within the textual statement; the keynames of the bindparams must match those within the text of the statement. The types will be used for pre-processing on bind values.
  • typemap – a dictionary mapping the names of columns represented in the columns clause of a SELECT statement to type objects, which will be used to perform post-processing on columns within the result set. This argument applies to any expression that returns result sets.
sqlalchemy.sql.expression.tuple_(*expr)

Return a SQL tuple.

Main usage is to produce a composite IN construct:

tuple_(table.c.col1, table.c.col2).in_(
    [(1, 2), (5, 12), (10, 19)]
)
sqlalchemy.sql.expression.type_coerce(expr, type_)

Coerce the given expression into the given type, on the Python side only.

type_coerce() is roughly similar to :func:.`cast`, except no “CAST” expression is rendered - the given type is only applied towards expression typing and against received result values.

e.g.:

from sqlalchemy.types import TypeDecorator
import uuid

class AsGuid(TypeDecorator):
    impl = String

    def process_bind_param(self, value, dialect):
        if value is not None:
            return str(value)
        else:
            return None

    def process_result_value(self, value, dialect):
        if value is not None:
            return uuid.UUID(value)
        else:
            return None

conn.execute(
    select([type_coerce(mytable.c.ident, AsGuid)]).\
            where(
                type_coerce(mytable.c.ident, AsGuid) == 
                uuid.uuid3(uuid.NAMESPACE_URL, 'bar')
            )
)
sqlalchemy.sql.expression.union(*selects, **kwargs)

Return a UNION of multiple selectables.

The returned object is an instance of CompoundSelect.

A similar union() method is available on all FromClause subclasses.

*selects
a list of Select instances.
**kwargs
available keyword arguments are the same as those of select().
sqlalchemy.sql.expression.union_all(*selects, **kwargs)

Return a UNION ALL of multiple selectables.

The returned object is an instance of CompoundSelect.

A similar union_all() method is available on all FromClause subclasses.

*selects
a list of Select instances.
**kwargs
available keyword arguments are the same as those of select().
sqlalchemy.sql.expression.update(table, whereclause=None, values=None, inline=False, **kwargs)

Return an Update clause element.

Similar functionality is available via the update() method on Table.

Parameters:
  • table – The table to be updated.
  • whereclause – A ClauseElement describing the WHERE condition of the UPDATE statement. Note that the where() generative method may also be used for this.
  • values – A dictionary which specifies the SET conditions of the UPDATE, and is optional. If left as None, the SET conditions are determined from the bind parameters used during the compile phase of the UPDATE statement. If the bind parameters also are None during the compile phase, then the SET conditions will be generated from the full list of table columns. Note that the values() generative method may also be used for this.
  • inline – if True, SQL defaults will be compiled ‘inline’ into the statement and not pre-executed.

If both values and compile-time bind parameters are present, the compile-time bind parameters override the information specified within values on a per-key basis.

The keys within values can be either Column objects or their string identifiers. Each key may reference one of:

  • a literal data value (i.e. string, number, etc.);
  • a Column object;
  • a SELECT statement.

If a SELECT statement is specified which references this UPDATE statement’s table, the statement will be correlated against the UPDATE statement.

Classes

class sqlalchemy.sql.expression.Alias(selectable, alias=None)

Bases: sqlalchemy.sql.expression.FromClause

Represents an table or selectable alias (AS).

Represents an alias, as typically applied to any table or sub-select within a SQL statement using the AS keyword (or without the keyword on certain databases such as Oracle).

This object is constructed from the alias() module level function as well as the FromClause.alias() method available on all FromClause subclasses.

class sqlalchemy.sql.expression._BindParamClause(key, value, type_=None, unique=False, isoutparam=False, required=False, _compared_to_operator=None, _compared_to_type=None)

Bases: sqlalchemy.sql.expression.ColumnElement

Represent a bind parameter.

Public constructor is the bindparam() function.

__init__(key, value, type_=None, unique=False, isoutparam=False, required=False, _compared_to_operator=None, _compared_to_type=None)

Construct a _BindParamClause.

Parameters:
  • key – the key for this bind param. Will be used in the generated SQL statement for dialects that use named parameters. This value may be modified when part of a compilation operation, if other _BindParamClause objects exist with the same key, or if its length is too long and truncation is required.
  • value – Initial value for this bind param. This value may be overridden by the dictionary of parameters sent to statement compilation/execution.
  • type_ – A TypeEngine object that will be used to pre-process the value corresponding to this _BindParamClause at execution time.
  • unique – if True, the key name of this BindParamClause will be modified if another _BindParamClause of the same name already has been located within the containing ClauseElement.
  • required – a value is required at execution time.
  • isoutparam – if True, the parameter should be treated like a stored procedure “OUT” parameter.
compare(other, **kw)

Compare this _BindParamClause to the given clause.

class sqlalchemy.sql.expression.ClauseElement

Bases: sqlalchemy.sql.visitors.Visitable

Base class for elements of a programmatically constructed SQL expression.

bind

Returns the Engine or Connection to which this ClauseElement is bound, or None if none found.

compare(other, **kw)

Compare this ClauseElement 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 ColumnElement)

compile(bind=None, dialect=None, **kw)

Compile this SQL expression.

The return value is a Compiled object. Calling str() or unicode() on the returned value will yield a string representation of the result. The Compiled object also can return a dictionary of bind parameter names and values using the params accessor.

Parameters:
  • bind – An Engine or Connection from which a Compiled will be acquired. This argument takes precedence over this ClauseElement‘s bound engine, if any.
  • column_keys – Used for INSERT and UPDATE statements, a list of column names which should be present in the VALUES clause of the compiled statement. If None, all columns from the target table object are rendered.
  • dialect – A Dialect instance frmo which a Compiled will be acquired. This argument takes precedence over the bind argument as well as this ClauseElement‘s bound engine, if any.
  • inline – Used for INSERT statements, for a dialect which does not support inline retrieval of newly generated primary key columns, will force the expression used to create the new primary key value to be rendered inline within the INSERT statement’s VALUES clause. This typically refers to Sequence execution but may also refer to any server-side default generation function associated with a primary key Column.
execute(*multiparams, **params)

Compile and execute this ClauseElement.

Deprecated since version 0.7: (pending) Only SQL expressions which subclass Executable may provide the execute() method.

get_children(**kwargs)

Return immediate child elements of this ClauseElement.

This is used for visit traversal.

**kwargs may contain flags that change the collection that is returned, for example to return a subset of items in order to cut down on larger traversals, or to return child items from a different context (such as schema-level collections instead of clause-level).

params(*optionaldict, **kwargs)

Return a copy with bindparam() elments replaced.

Returns a copy of this ClauseElement with bindparam() elements replaced with values taken from the given dictionary:

>>> clause = column('x') + bindparam('foo')
>>> print clause.compile().params
{'foo':None}
>>> print clause.params({'foo':7}).compile().params
{'foo':7}
scalar(*multiparams, **params)

Compile and execute this ClauseElement, returning

Deprecated since version 0.7: (pending) Only SQL expressions which subclass Executable may provide the scalar() method.

the result’s scalar representation.

self_group(against=None)

Apply a ‘grouping’ to this ClauseElement.

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 select(). (Note that subqueries should be normally created using the Select.alias() method, as many platforms require nested SELECT statements to be named).

As expressions are composed together, the application of self_group() 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 ClauseElement just returns self.

unique_params(*optionaldict, **kwargs)

Return a copy with bindparam() elments replaced.

Same functionality as params(), except adds unique=True to affected bind parameters so that multiple statements can be used.

class sqlalchemy.sql.expression.ColumnClause(text, selectable=None, type_=None, is_literal=False)

Bases: sqlalchemy.sql.expression._Immutable, sqlalchemy.sql.expression.ColumnElement

Represents a generic column expression from any textual string.

This includes columns associated with tables, aliases and select statements, but also any arbitrary text. May or may not be bound to an underlying Selectable.

ColumnClause is constructed by itself typically via the column() function. It may be placed directly into constructs such as select() constructs:

from sqlalchemy.sql import column, select

c1, c2 = column("c1"), column("c2")
s = select([c1, c2]).where(c1==5)

There is also a variant on column() known as literal_column() - the difference is that in the latter case, the string value is assumed to be an exact expression, rather than a column name, so that no quoting rules or similar are applied:

from sqlalchemy.sql import literal_column, select

s = select([literal_column("5 + 7")])

ColumnClause can also be used in a table-like fashion by combining the column() function with the table() function, to produce a “lightweight” form of table metadata:

from sqlalchemy.sql import table, column

user = table("user",
        column("id"),
        column("name"),
        column("description"),
)

The above construct can be created in an ad-hoc fashion and is not associated with any schema.MetaData, unlike it’s more full fledged schema.Table counterpart.

Parameters:
  • text – the text of the element.
  • selectable – parent selectable.
  • typetypes.TypeEngine object which can associate this ColumnClause with a type.
  • is_literal – if True, the ColumnClause is assumed to be an exact expression that will be delivered to the output with no quoting rules applied regardless of case sensitive settings. the literal_column() function is usually used to create such a ColumnClause.
class sqlalchemy.sql.expression.ColumnCollection(*cols)

Bases: sqlalchemy.util.OrderedProperties

An ordered dictionary that stores a list of ColumnElement instances.

Overrides the __eq__() method to produce SQL clauses between sets of correlated columns.

add(column)

Add a column to this collection.

The key attribute of the column will be used as the hash key for this dictionary.

replace(column)

add the given column to this collection, removing unaliased versions of this column as well as existing columns with the same key.

e.g.:

t = Table('sometable', metadata, Column('col1', Integer))
t.columns.replace(Column('col1', Integer, key='columnone'))

will remove the original ‘col1’ from the collection, and add the new column under the name ‘columnname’.

Used by schema.Column to override columns during table reflection.

class sqlalchemy.sql.expression.ColumnElement

Bases: sqlalchemy.sql.expression.ClauseElement, sqlalchemy.sql.expression._CompareMixin

Represent an element that is usable within the “column clause” portion of a SELECT statement.

This includes columns associated with tables, aliases, and subqueries, expressions, function calls, SQL keywords such as NULL, literals, etc. ColumnElement is the ultimate base class for all such elements.

ColumnElement supports the ability to be a proxy element, which indicates that the ColumnElement may be associated with a Selectable which was derived from another Selectable. An example of a “derived” Selectable is an Alias of a Table.

A ColumnElement, by subclassing the _CompareMixin mixin class, provides the ability to generate new ClauseElement objects using Python expressions. See the _CompareMixin docstring for more details.

anon_label

provides a constant ‘anonymous label’ for this ColumnElement.

This is a label() expression which will be named at compile time. The same label() is returned each time anon_label is called so that expressions can reference anon_label multiple times, producing the same label name at compile time.

the compiler uses this function automatically at compile time for expressions that are known to be ‘unnamed’ like binary expressions and function calls.

compare(other, use_proxies=False, equivalents=None, **kw)

Compare this ColumnElement to another.

Special arguments understood:

Parameters:
  • use_proxies – when True, consider two columns that share a common base column as equivalent (i.e. shares_lineage())
  • equivalents – a dictionary of columns as keys mapped to sets of columns. If the given “other” column is present in this dictionary, if any of the columns in the correponding set() pass the comparison test, the result is True. This is used to expand the comparison to other columns that may be known to be equivalent to this one via foreign key or other criterion.
shares_lineage(othercolumn)

Return True if the given ColumnElement has a common ancestor to this ColumnElement.

class sqlalchemy.sql.expression._CompareMixin

Bases: sqlalchemy.sql.expression.ColumnOperators

Defines comparison and math operations for ClauseElement instances.

asc()

Produce a ASC clause, i.e. <columnname> ASC

between(cleft, cright)

Produce a BETWEEN clause, i.e. <column> BETWEEN <cleft> AND <cright>

collate(collation)

Produce a COLLATE clause, i.e. <column> COLLATE utf8_bin

contains(other, escape=None)

Produce the clause LIKE '%<other>%'

desc()

Produce a DESC clause, i.e. <columnname> DESC

distinct()

Produce a DISTINCT clause, i.e. DISTINCT <columnname>

endswith(other, escape=None)

Produce the clause LIKE '%<other>'

in_(other)

Compare this element to the given element or collection using IN.

label(name)

Produce a column label, i.e. <columnname> AS <name>.

This is a shortcut to the label() function.

if ‘name’ is None, an anonymous label name will be generated.

match(other)

Produce a MATCH clause, i.e. MATCH '<other>'

The allowed contents of other are database backend specific.

op(operator)

produce a generic operator function.

e.g.:

somecolumn.op("*")(5)

produces:

somecolumn * 5
Parameters:operator – a string which will be output as the infix operator between this ClauseElement and the expression passed to the generated function.

This function can also be used to make bitwise operators explicit. For example:

somecolumn.op('&')(0xff)

is a bitwise AND of the value in somecolumn.

operate(op, *other, **kwargs)
operators = {<function like_op at 0x2b36f6f3c488>: (<function __compare at 0x2b36f6f4aaa0>, <function notlike_op at 0x2b36f6f3c500>), <built-in function eq>: (<function __compare at 0x2b36f6f4aaa0>, <built-in function ne>), <built-in function mul>: (<function __operate at 0x2b36f6f4ab18>,), <built-in function mod>: (<function __operate at 0x2b36f6f4ab18>,), <function ilike_op at 0x2b36f6f3c578>: (<function __compare at 0x2b36f6f4aaa0>, <function notilike_op at 0x2b36f6f3c5f0>), <built-in function truediv>: (<function __operate at 0x2b36f6f4ab18>,), <built-in function div>: (<function __operate at 0x2b36f6f4ab18>,), <built-in function ge>: (<function __compare at 0x2b36f6f4aaa0>, <built-in function lt>), <built-in function sub>: (<function __operate at 0x2b36f6f4ab18>,), <built-in function gt>: (<function __compare at 0x2b36f6f4aaa0>, <built-in function le>), <built-in function add>: (<function __operate at 0x2b36f6f4ab18>,), <built-in function ne>: (<function __compare at 0x2b36f6f4aaa0>, <built-in function eq>), <built-in function le>: (<function __compare at 0x2b36f6f4aaa0>, <built-in function gt>), <built-in function lt>: (<function __compare at 0x2b36f6f4aaa0>, <built-in function ge>)}
reverse_operate(op, other, **kwargs)
startswith(other, escape=None)

Produce the clause LIKE '<other>%'

class sqlalchemy.sql.expression.ColumnOperators

Defines comparison and math operations.

__init__

x.__init__(...) initializes x; see help(type(x)) for signature

asc()
between(cleft, cright)
collate(collation)
concat(other)
contains(other, **kwargs)
desc()
distinct()
endswith(other, **kwargs)
ilike(other, escape=None)
in_(other)
like(other, escape=None)
match(other, **kwargs)
op(opstring)
operate(op, *other, **kwargs)
reverse_operate(op, other, **kwargs)
startswith(other, **kwargs)
timetuple = None

Hack, allows datetime objects to be compared on the LHS.

class sqlalchemy.sql.expression.CompoundSelect(keyword, *selects, **kwargs)

Bases: sqlalchemy.sql.expression._SelectBaseMixin, sqlalchemy.sql.expression.FromClause

Forms the basis of UNION, UNION ALL, and other SELECT-based set operations.

class sqlalchemy.sql.expression.Delete(table, whereclause, bind=None, returning=None, **kwargs)

Bases: sqlalchemy.sql.expression._UpdateBase

Represent a DELETE construct.

The Delete object is created using the delete() function.

where(whereclause)

Add the given WHERE clause to a newly returned delete construct.

class sqlalchemy.sql.expression.Executable

Bases: sqlalchemy.sql.expression._Generative

Mark a ClauseElement as supporting execution.

Executable is a superclass for all “statement” types of objects, including select(), delete(), update(), insert(), text().

execute(*multiparams, **params)

Compile and execute this Executable.

execution_options(**kw)

Set non-SQL options for the statement which take effect during execution.

Current options include:

  • autocommit - when True, a COMMIT will be invoked after execution when executed in ‘autocommit’ mode, i.e. when an explicit transaction is not begun on the connection. Note that DBAPI connections by default are always in a transaction - SQLAlchemy uses rules applied to different kinds of statements to determine if COMMIT will be invoked in order to provide its “autocommit” feature. Typically, all INSERT/UPDATE/DELETE statements as well as CREATE/DROP statements have autocommit behavior enabled; SELECT constructs do not. Use this option when invoking a SELECT or other specific SQL construct where COMMIT is desired (typically when calling stored procedures and such).

  • stream_results - indicate to the dialect that results should be “streamed” and not pre-buffered, if possible. This is a limitation of many DBAPIs. The flag is currently understood only by the psycopg2 dialect.

  • compiled_cache - a dictionary where Compiled objects will be cached when the Connection compiles a clause expression into a dialect- and parameter-specific Compiled object. It is the user’s responsibility to manage the size of this dictionary, which will have keys corresponding to the dialect, clause element, the column names within the VALUES or SET clause of an INSERT or UPDATE, as well as the “batch” mode for an INSERT or UPDATE statement. The format of this dictionary is not guaranteed to stay the same in future releases.

    This option is usually more appropriate to use via the sqlalchemy.engine.base.Connection.execution_options() method of Connection, rather than upon individual statement objects, though the effect is the same.

See also:

scalar(*multiparams, **params)

Compile and execute this Executable, returning the result’s scalar representation.

class sqlalchemy.sql.expression.FunctionElement(*clauses, **kwargs)

Bases: sqlalchemy.sql.expression.Executable, sqlalchemy.sql.expression.ColumnElement, sqlalchemy.sql.expression.FromClause

Base for SQL function-oriented constructs.

class sqlalchemy.sql.expression.Function(name, *clauses, **kw)

Bases: sqlalchemy.sql.expression.FunctionElement

Describe a named SQL function.

class sqlalchemy.sql.expression.FromClause

Bases: sqlalchemy.sql.expression.Selectable

Represent an element that can be used within the FROM clause of a SELECT statement.

alias(name=None)

return an alias of this FromClause.

This is shorthand for calling:

from sqlalchemy import alias
a = alias(self, name)

See alias() for details.

c

Return the collection of Column objects contained by this FromClause.

columns

Return the collection of Column objects contained by this FromClause.

correspond_on_equivalents(column, equivalents)

Return corresponding_column for the given column, or if None search for a match in the given dictionary.

corresponding_column(column, require_embedded=False)

Given a ColumnElement, return the exported ColumnElement object from this Selectable which corresponds to that original Column via a common anscestor column.

Parameters:
  • column – the target ColumnElement to be matched
  • require_embedded – only return corresponding columns for

the given ColumnElement, if the given ColumnElement is actually present within a sub-element of this FromClause. Normally the column will match if it merely shares a common anscestor with one of the exported columns of this FromClause.

count(whereclause=None, **params)

return a SELECT COUNT generated against this FromClause.

description

a brief description of this FromClause.

Used primarily for error message formatting.

foreign_keys

Return the collection of ForeignKey objects which this FromClause references.

is_derived_from(fromclause)

Return True if this FromClause is ‘derived’ from the given FromClause.

An example would be an Alias of a Table is derived from that Table.

join(right, onclause=None, isouter=False)

return a join of this FromClause against another FromClause.

outerjoin(right, onclause=None)

return an outer join of this FromClause against another FromClause.

primary_key

Return the collection of Column objects which comprise the primary key of this FromClause.

replace_selectable(old, alias)

replace all occurrences of FromClause ‘old’ with the given Alias object, returning a copy of this FromClause.

select(whereclause=None, **params)

return a SELECT of this FromClause.

class sqlalchemy.sql.expression.Insert(table, values=None, inline=False, bind=None, prefixes=None, returning=None, **kwargs)

Bases: sqlalchemy.sql.expression._ValuesBase

Represent an INSERT construct.

The Insert object is created using the insert() function.

prefix_with(clause)

Add a word or expression between INSERT and INTO. Generative.

If multiple prefixes are supplied, they will be separated with spaces.

values(*args, **kwargs)

specify the VALUES clause for an INSERT statement, or the SET clause for an UPDATE.

**kwargs
key=<somevalue> arguments
*args
A single dictionary can be sent as the first positional argument. This allows non-string based keys, such as Column objects, to be used.
class sqlalchemy.sql.expression.Join(left, right, onclause=None, isouter=False)

Bases: sqlalchemy.sql.expression.FromClause

represent a JOIN construct between two FromClause elements.

The public constructor function for Join is the module-level join() function, as well as the join() method available off all FromClause subclasses.

__init__(left, right, onclause=None, isouter=False)

Construct a new Join.

The usual entrypoint here is the join() function or the FromClause.join() method of any FromClause object.

alias(name=None)

return an alias of this Join.

Used against a Join object, alias() calls the select() method first so that a subquery against a select() construct is generated. the select() construct also has the correlate flag set to False and will not auto-correlate inside an enclosing select() construct.

The equivalent long-hand form, given a Join object j, is:

from sqlalchemy import select, alias
j = alias(
    select([j.left, j.right]).\
        select_from(j).\
        with_labels(True).\
        correlate(False),
    name
)

See alias() for further details on aliases.

select(whereclause=None, fold_equivalents=False, **kwargs)

Create a Select from this Join.

The equivalent long-hand form, given a Join object j, is:

from sqlalchemy import select
j = select([j.left, j.right], **kw).\
            where(whereclause).\
            select_from(j)
Parameters:
  • whereclause – the WHERE criterion that will be sent to the select() function
  • fold_equivalents – based on the join criterion of this Join, do not include repeat column names in the column list of the resulting select, for columns that are calculated to be “equivalent” based on the join criterion of this Join. This will recursively apply to any joins directly nested by this one as well.
  • **kwargs – all other kwargs are sent to the underlying select() function.
class sqlalchemy.sql.expression.Select(columns, whereclause=None, from_obj=None, distinct=False, having=None, correlate=True, prefixes=None, **kwargs)

Bases: sqlalchemy.sql.expression._SelectBaseMixin, sqlalchemy.sql.expression.FromClause

Represents a SELECT statement.

Select statements support appendable clauses, as well as the ability to execute themselves and return a result set.

__init__(columns, whereclause=None, from_obj=None, distinct=False, having=None, correlate=True, prefixes=None, **kwargs)

Construct a Select object.

The public constructor for Select is the select() function; see that function for argument descriptions.

Additional generative and mutator methods are available on the _SelectBaseMixin superclass.

append_column(column)

append the given column expression to the columns clause of this select() construct.

append_correlation(fromclause)

append the given correlation expression to this select() construct.

append_from(fromclause)

append the given FromClause expression to this select() construct’s FROM clause.

append_having(having)

append the given expression to this select() construct’s HAVING criterion.

The expression will be joined to existing HAVING criterion via AND.

append_prefix(clause)

append the given columns clause prefix expression to this select() construct.

append_whereclause(whereclause)

append the given expression to this select() construct’s WHERE criterion.

The expression will be joined to existing WHERE criterion via AND.

column(column)

return a new select() construct with the given column expression added to its columns clause.

correlate(*fromclauses)

return a new select() construct which will correlate the given FROM clauses to that of an enclosing select(), if a match is found.

By “match”, the given fromclause must be present in this select’s list of FROM objects and also present in an enclosing select’s list of FROM objects.

Calling this method turns off the select’s default behavior of “auto-correlation”. Normally, select() auto-correlates all of its FROM clauses to those of an embedded select when compiled.

If the fromclause is None, correlation is disabled for the returned select().

distinct()

return a new select() construct which will apply DISTINCT to its columns clause.

except_(other, **kwargs)

return a SQL EXCEPT of this select() construct against the given selectable.

except_all(other, **kwargs)

return a SQL EXCEPT ALL of this select() construct against the given selectable.

froms

Return the displayed list of FromClause elements.

get_children(column_collections=True, **kwargs)

return child elements as per the ClauseElement specification.

having(having)

return a new select() construct with the given expression added to its HAVING clause, joined to the existing clause via AND, if any.

inner_columns

an iterator of all ColumnElement expressions which would be rendered into the columns clause of the resulting SELECT statement.

intersect(other, **kwargs)

return a SQL INTERSECT of this select() construct against the given selectable.

intersect_all(other, **kwargs)

return a SQL INTERSECT ALL of this select() construct against the given selectable.

locate_all_froms

return a Set of all FromClause elements referenced by this Select.

This set is a superset of that returned by the froms property,

which is specifically for those FromClause elements that would actually be rendered.

prefix_with(clause)

return a new select() construct which will apply the given expression to the start of its columns clause, not using any commas.

select_from(fromclause)

return a new Select construct with the given FROM expression merged into its list of FROM objects.

The “from” list is a unique set on the identity of each element, so adding an already present Table or other selectable will have no effect. Passing a Join that refers to an already present Table or other selectable will have the effect of concealing the presence of that selectable as an individual element in the rendered FROM list, instead rendering it into a JOIN clause.

self_group(against=None)

return a ‘grouping’ construct as per the ClauseElement specification.

This produces an element that can be embedded in an expression. Note

that this method is called automatically as needed when constructing expressions.

union(other, **kwargs)

return a SQL UNION of this select() construct against the given selectable.

union_all(other, **kwargs)

return a SQL UNION ALL of this select() construct against the given selectable.

where(whereclause)

return a new select() construct with the given expression added to its WHERE clause, joined to the existing clause via AND, if any.

with_hint(selectable, text, dialect_name='*')

Add an indexing hint for the given selectable to this Select.

The text of the hint is rendered in the appropriate location for the database backend in use, relative to the given Table or Alias passed as the selectable argument. The dialect implementation typically uses Python string substitution syntax with the token %(name)s to render the name of the table or alias. E.g. when using Oracle, the following:

select([mytable]).\
    with_hint(mytable, "+ index(%(name)s ix_mytable)")

Would render SQL as:

select /*+ index(mytable ix_mytable) */ ... from mytable

The dialect_name option will limit the rendering of a particular hint to a particular backend. Such as, to add hints for both Oracle and Sybase simultaneously:

select([mytable]).\
    with_hint(mytable, "+ index(%(name)s ix_mytable)", 'oracle').\
    with_hint(mytable, "WITH INDEX ix_mytable", 'sybase')
with_only_columns(columns)

return a new select() construct with its columns clause replaced with the given columns.

class sqlalchemy.sql.expression.Selectable

Bases: sqlalchemy.sql.expression.ClauseElement

mark a class as being selectable

class sqlalchemy.sql.expression._SelectBaseMixin(use_labels=False, for_update=False, limit=None, offset=None, order_by=None, group_by=None, bind=None, autocommit=None)

Bases: sqlalchemy.sql.expression.Executable

Base class for Select and CompoundSelects.

append_group_by(*clauses)

Append the given GROUP BY criterion applied to this selectable.

The criterion will be appended to any pre-existing GROUP BY criterion.

append_order_by(*clauses)

Append the given ORDER BY criterion applied to this selectable.

The criterion will be appended to any pre-existing ORDER BY criterion.

apply_labels()

return a new selectable with the ‘use_labels’ flag set to True.

This will result in column expressions being generated using labels against their table name, such as “SELECT somecolumn AS tablename_somecolumn”. This allows selectables which contain multiple FROM clauses to produce a unique set of column names regardless of name conflicts among the individual FROM clauses.

as_scalar()

return a ‘scalar’ representation of this selectable, which can be used as a column expression.

Typically, a select statement which has only one column in its columns clause is eligible to be used as a scalar expression.

The returned object is an instance of _ScalarSelect.

autocommit()

return a new selectable with the ‘autocommit’ flag set to

Deprecated since version 0.6: autocommit() is deprecated. Use Executable.execution_options() with the ‘autocommit’ flag.

True.

group_by(*clauses)

return a new selectable with the given list of GROUP BY criterion applied.

The criterion will be appended to any pre-existing GROUP BY criterion.

label(name)

return a ‘scalar’ representation of this selectable, embedded as a subquery with a label.

See also as_scalar().

limit(limit)

return a new selectable with the given LIMIT criterion applied.

offset(offset)

return a new selectable with the given OFFSET criterion applied.

order_by(*clauses)

return a new selectable with the given list of ORDER BY criterion applied.

The criterion will be appended to any pre-existing ORDER BY criterion.

class sqlalchemy.sql.expression.TableClause(name, *columns)

Bases: sqlalchemy.sql.expression._Immutable, sqlalchemy.sql.expression.FromClause

Represents a minimal “table” construct.

The constructor for TableClause is the table() function. This produces a lightweight table object that has only a name and a collection of columns, which are typically produced by the column() function:

from sqlalchemy.sql import table, column

user = table("user",
        column("id"),
        column("name"),
        column("description"),
)

The TableClause construct serves as the base for the more commonly used Table object, providing the usual set of FromClause services including the .c. collection and statement generation methods.

It does not provide all the additional schema-level services of Table, including constraints, references to other tables, or support for MetaData-level services. It’s useful on its own as an ad-hoc construct used to generate quick SQL statements when a more fully fledged Table is not on hand.

count(whereclause=None, **params)

return a SELECT COUNT generated against this TableClause.

delete(whereclause=None, **kwargs)

Generate a delete() construct.

insert(values=None, inline=False, **kwargs)

Generate an insert() construct.

update(whereclause=None, values=None, inline=False, **kwargs)

Generate an update() construct.

class sqlalchemy.sql.expression.Update(table, whereclause, values=None, inline=False, bind=None, returning=None, **kwargs)

Bases: sqlalchemy.sql.expression._ValuesBase

Represent an Update construct.

The Update object is created using the update() function.

where(whereclause)

return a new update() construct with the given expression added to its WHERE clause, joined to the existing clause via AND, if any.

values(*args, **kwargs)

specify the VALUES clause for an INSERT statement, or the SET clause for an UPDATE.

**kwargs
key=<somevalue> arguments
*args
A single dictionary can be sent as the first positional argument. This allows non-string based keys, such as Column objects, to be used.

Generic Functions

SQL functions which are known to SQLAlchemy with regards to database-specific rendering, return types and argument behavior. Generic functions are invoked like all SQL functions, using the func attribute:

select([func.count()]).select_from(sometable)

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.

class sqlalchemy.sql.functions.AnsiFunction(**kwargs)

Bases: sqlalchemy.sql.functions.GenericFunction

class sqlalchemy.sql.functions.GenericFunction(type_=None, args=(), **kwargs)

Bases: sqlalchemy.sql.expression.Function

class sqlalchemy.sql.functions.ReturnTypeFromArgs(*args, **kwargs)

Bases: sqlalchemy.sql.functions.GenericFunction

Define a function whose return type is the same as its arguments.

class sqlalchemy.sql.functions.char_length(arg, **kwargs)

Bases: sqlalchemy.sql.functions.GenericFunction

class sqlalchemy.sql.functions.coalesce(*args, **kwargs)

Bases: sqlalchemy.sql.functions.ReturnTypeFromArgs

class sqlalchemy.sql.functions.concat(*args, **kwargs)

Bases: sqlalchemy.sql.functions.GenericFunction

class sqlalchemy.sql.functions.count(expression=None, **kwargs)

Bases: sqlalchemy.sql.functions.GenericFunction

The ANSI COUNT aggregate function. With no arguments, emits COUNT *.

class sqlalchemy.sql.functions.current_date(**kwargs)

Bases: sqlalchemy.sql.functions.AnsiFunction

class sqlalchemy.sql.functions.current_time(**kwargs)

Bases: sqlalchemy.sql.functions.AnsiFunction

class sqlalchemy.sql.functions.current_timestamp(**kwargs)

Bases: sqlalchemy.sql.functions.AnsiFunction

class sqlalchemy.sql.functions.current_user(**kwargs)

Bases: sqlalchemy.sql.functions.AnsiFunction

class sqlalchemy.sql.functions.localtime(**kwargs)

Bases: sqlalchemy.sql.functions.AnsiFunction

class sqlalchemy.sql.functions.localtimestamp(**kwargs)

Bases: sqlalchemy.sql.functions.AnsiFunction

class sqlalchemy.sql.functions.max(*args, **kwargs)

Bases: sqlalchemy.sql.functions.ReturnTypeFromArgs

class sqlalchemy.sql.functions.min(*args, **kwargs)

Bases: sqlalchemy.sql.functions.ReturnTypeFromArgs

class sqlalchemy.sql.functions.now(type_=None, args=(), **kwargs)

Bases: sqlalchemy.sql.functions.GenericFunction

class sqlalchemy.sql.functions.random(*args, **kwargs)

Bases: sqlalchemy.sql.functions.GenericFunction

class sqlalchemy.sql.functions.session_user(**kwargs)

Bases: sqlalchemy.sql.functions.AnsiFunction

class sqlalchemy.sql.functions.sum(*args, **kwargs)

Bases: sqlalchemy.sql.functions.ReturnTypeFromArgs

class sqlalchemy.sql.functions.sysdate(**kwargs)

Bases: sqlalchemy.sql.functions.AnsiFunction

class sqlalchemy.sql.functions.user(**kwargs)

Bases: sqlalchemy.sql.functions.AnsiFunction