Defines the public namespace for SQL expression constructs.
Prior to version 0.9, this module contained all of "elements", "dml", "default_comparator" and "selectable". The module was broken up and most "factory" functions were moved to be grouped with their associated class.
Class | Alias |
Represents an table or selectable alias (AS). |
Class | AliasedReturnsRows |
Base class of aliases against tables, subqueries, and other selectables. |
Class | CacheKey |
The key used to identify a SQL statement construct in the SQL compilation cache. |
Class | ClauseElement |
Base class for elements of a programmatically constructed SQL expression. |
Class | ColumnCollection |
Collection of _expression.ColumnElement instances, typically for _sql.FromClause objects. |
Class | ColumnElement |
Represent a column-oriented SQL expression suitable for usage in the "columns" clause, WHERE clause etc. of a statement. |
Class | CompoundSelect |
Forms the basis of UNION, UNION ALL, and other SELECT-based set operations. |
Class | custom_op |
Represent a 'custom' operator. |
Class | Delete |
Represent a DELETE construct. |
Class | FromClause |
Represent an element that can be used within the FROM clause of a SELECT statement. |
Class | Insert |
Represent an INSERT construct. |
Class | Join |
Represent a JOIN construct between two _expression.FromClause elements. |
Class | LambdaElement |
A SQL construct where the state is stored as an un-invoked lambda. |
Class | Lateral |
Represent a LATERAL subquery. |
Class | quoted_name |
Represent a SQL identifier combined with quoting preferences. |
Class | Select |
Represents a SELECT statement. |
Class | Selectable |
Mark a class as being selectable. |
Class | StatementLambdaElement |
Represent a composable SQL statement as a _sql.LambdaElement . |
Class | Subquery |
Represent a subquery of a SELECT. |
Class | TableClause |
Represents a minimal "table" construct. |
Class | TableSample |
Represent a TABLESAMPLE clause. |
Class | TableValuedAlias |
An alias against a "table valued" SQL function. |
Class | Update |
Represent an Update construct. |
Class | Values |
Represent a VALUES construct that can be used as a FROM element in a statement. |
Function | between |
Produce a BETWEEN predicate clause. |
Function | collate |
Return the clause expression COLLATE collation. |
Function | lambda_stmt |
Produce a SQL statement that is cached as a lambda. |
Function | literal |
Return a literal clause, bound to a bind parameter. |
Function | literal_column |
Produce a .ColumnClause object that has the :paramref:`_expression.column.is_literal` flag set to True. |
Function | not_ |
Return a negation of the given clause, i.e. NOT(clause). |
Function | outparam |
Create an 'OUT' parameter for usage in functions (stored procedures), for databases which support them. |
Variable | alias |
Undocumented |
Variable | all_ |
Undocumented |
Variable | and_ |
Undocumented |
Variable | any_ |
Undocumented |
Variable | asc |
Undocumented |
Variable | bindparam |
Undocumented |
Variable | case |
Undocumented |
Variable | cast |
Undocumented |
Variable | column |
Undocumented |
Variable | cte |
Undocumented |
Variable | delete |
Undocumented |
Variable | desc |
Undocumented |
Variable | distinct |
Undocumented |
Variable | except_ |
Undocumented |
Variable | except_all |
Undocumented |
Variable | exists |
Undocumented |
Variable | extract |
Undocumented |
Variable | false |
Undocumented |
Variable | func |
Undocumented |
Variable | funcfilter |
Undocumented |
Variable | insert |
Undocumented |
Variable | intersect |
Undocumented |
Variable | intersect_all |
Undocumented |
Variable | join |
Undocumented |
Variable | label |
Undocumented |
Variable | lateral |
Undocumented |
Variable | modifier |
Undocumented |
Variable | null |
Undocumented |
Variable | nulls_first |
Undocumented |
Variable | nulls_last |
Undocumented |
Variable | or_ |
Undocumented |
Variable | outerjoin |
Undocumented |
Variable | over |
Undocumented |
Variable | select |
Undocumented |
Variable | table |
Undocumented |
Variable | tablesample |
Undocumented |
Variable | text |
Undocumented |
Variable | true |
Undocumented |
Variable | tuple_ |
Undocumented |
Variable | type_coerce |
Undocumented |
Variable | union |
Undocumented |
Variable | union_all |
Undocumented |
Variable | update |
Undocumented |
Variable | values |
Undocumented |
Variable | within_group |
Undocumented |
Produce a BETWEEN predicate clause.
E.g.:
from sqlalchemy import between stmt = select(users_table).where(between(users_table.c.id, 5, 7))
Would produce SQL resembling:
SELECT id, name FROM user WHERE id BETWEEN :id_1 AND :id_2
The .between
function is a standalone version of the
_expression.ColumnElement.between
method available on all
SQL expressions, as in:
stmt = select(users_table).where(users_table.c.id.between(5, 7))
All arguments passed to .between
, including the left side
column expression, are coerced from Python scalar values if a
the value is not a _expression.ColumnElement
subclass.
For example,
three fixed values can be compared as in:
print(between(5, 3, 7))
Which would produce:
:param_1 BETWEEN :param_2 AND :param_3
See Also
_expression.ColumnElement.between
Parameters | |
expr | a column expression, typically a
_expression.ColumnElement
instance or alternatively a Python scalar expression to be coerced
into a column expression, serving as the left side of the BETWEEN
expression. |
lower_bound | a column or Python scalar expression serving as the lower bound of the right side of the BETWEEN expression. |
upper_bound | a column or Python scalar expression serving as the upper bound of the right side of the BETWEEN expression. |
symmetric | if True, will render " BETWEEN SYMMETRIC ". Note that not all databases support this syntax.
New in version 0.9.5.
|
Return the clause expression COLLATE collation.
e.g.:
collate(mycolumn, 'utf8_bin')
produces:
mycolumn COLLATE utf8_bin
The collation expression is also quoted if it is a case sensitive identifier, e.g. contains uppercase characters.
Produce a SQL statement that is cached as a lambda.
The Python code object within the lambda is scanned for both Python literals that will become bound parameters as well as closure variables that refer to Core or ORM constructs that may vary. The lambda itself will be invoked only once per particular set of constructs detected.
E.g.:
from sqlalchemy import lambda_stmt stmt = lambda_stmt(lambda: table.select()) stmt += lambda s: s.where(table.c.id == 5) result = connection.execute(stmt)
The object returned is an instance of _sql.StatementLambdaElement
.
See Also
Parameters | |
lmb | a Python function, typically a lambda, which takes no arguments and returns a SQL expression construct |
enable_tracking | when False, all scanning of the given lambda for changes in closure variables or bound parameters is disabled. Use for a lambda that produces the identical results in all cases with no parameterization. |
track_closure_variables | when False, changes in closure variables within the lambda will not be scanned. Use for a lambda where the state of its closure variables will never change the SQL structure returned by the lambda. |
track_on | Undocumented |
global_track_bound_values | when False, bound parameter tracking
will be disabled for the entire statement including additional links
added via the _sql.StatementLambdaElement.add_criteria method. |
track_bound_values | when False, bound parameter tracking will be disabled for the given lambda. Use for a lambda that either does not produce any bound values, or where the initial bound values never change. |
lambda_cache | a dictionary or other mapping-like object where
information about the lambda's Python code as well as the tracked closure
variables in the lambda itself will be stored. Defaults
to a global LRU cache. This cache is independent of the "compiled_cache"
used by the _engine.Connection object. |
Return a literal clause, bound to a bind parameter.
Literal clauses are created automatically when non-
_expression.ClauseElement
objects (such as strings, ints, dates,
etc.) are
used in a comparison operation with a _expression.ColumnElement
subclass,
such as a ~sqlalchemy.schema.Column
object. Use this function
to force the generation of a literal clause, which will be created as a
BindParameter
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 ~sqlalchemy.types.TypeEngine which
will provide bind-parameter translation for this literal. |
Produce a .ColumnClause
object that has the
:paramref:`_expression.column.is_literal` flag set to True.
_expression.literal_column
is similar to
_expression.column
, except that
it is more often used as a "standalone" column expression that renders
exactly as stated; while _expression.column
stores a string name that
will be assumed to be part of a table and may be quoted as such,
_expression.literal_column
can be that,
or any other arbitrary column-oriented
expression.
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 ~sqlalchemy.types.TypeEngine
object which will
provide result-set translation and additional expression semantics for
this column. If left as None the type will be .NullType . |
Return a negation of the given clause, i.e. NOT(clause).
The ~ operator is also overloaded on all
_expression.ColumnElement
subclasses to produce the
same result.
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
~sqlalchemy.engine.CursorResult
object via its out_parameters
attribute, which returns a dictionary containing the values.