class documentation

class ScalarSelect(roles.InElementRole, Generative, Grouping):

View In Hierarchy

Represent a scalar subquery.

A _sql.ScalarSelect is created by invoking the _sql.SelectBase.scalar_subquery method. The object then participates in other SQL expressions as a SQL column expression within the _sql.ColumnElement hierarchy.

See Also

_sql.SelectBase.scalar_subquery

:ref:`tutorial_scalar_subquery` - in the 2.0 tutorial

:ref:`scalar_selects` - in the 1.x tutorial

Method __init__ Undocumented
Method correlate Return a new _expression.ScalarSelect which will correlate the given FROM clauses to that of an enclosing _expression.Select.
Method correlate​_except Return a new _expression.ScalarSelect which will omit the given FROM clauses from the auto-correlation process.
Method self​_group Apply a 'grouping' to this _expression.ClauseElement.
Method where Apply a WHERE clause to the SELECT statement referred to by this _expression.ScalarSelect.
Class Variable ​_from​_objects Undocumented
Class Variable ​_is​_from​_container Undocumented
Class Variable ​_is​_implicitly​_boolean Undocumented
Class Variable inherit​_cache Indicate if this .HasCacheKey instance should make use of the cache key generation scheme used by its immediate superclass.
Instance Variable element Undocumented
Instance Variable type Undocumented
Property columns Undocumented

Inherited from InElementRole:

Class Variable ​_role​_name Undocumented

Inherited from SQLRole (via InElementRole):

Class Variable allows​_lambda Undocumented
Class Variable uses​_inspection Undocumented

Inherited from Generative:

Method ​_generate Undocumented

Inherited from Grouping:

Method __getattr__ Undocumented
Method __getstate__ Undocumented
Method __setstate__ Undocumented
Method ​_with​_binary​_element​_type in the context of binary expression, convert the type of this object to the one given.
Class Variable ​_traverse​_internals Undocumented
Property ​_proxies Undocumented
Property ​_tq​_label The named label that can be used to target this column in a result set in a "table qualified" context.

Inherited from GroupedElement (via Grouping):

Method ​_ungroup Return this _expression.ClauseElement without any groupings.
Class Variable __visit​_name__ Undocumented

Inherited from ClauseElement (via Grouping, GroupedElement):

Method compare Compare this _expression.ClauseElement to the given _expression.ClauseElement.
Method compile Compile this SQL expression.
Method params Return a copy with _expression.bindparam elements replaced.
Method unique​_params Return a copy with _expression.bindparam elements replaced.
Method __bool__ Undocumented
Method __invert__ Undocumented
Method __repr__ Undocumented
Method __str__ Undocumented
Method ​_clone Create a shallow copy of this ClauseElement.
Method ​_cloned​_set Return the set consisting all cloned ancestors of this ClauseElement.
Method ​_compile​_w​_cache Undocumented
Method ​_compiler Return a compiler appropriate for this ClauseElement, given a Dialect.
Method ​_execute​_on​_connection Undocumented
Method ​_negate Undocumented
Method ​_negate​_in​_binary a hook to allow the right side of a binary expression to respond to a negation of the binary expression.
Method ​_replace​_params Undocumented
Method ​_set​_propagate​_attrs Undocumented
Class Variable ​_cache​_key​_traversal Undocumented
Class Variable ​_is​_bind​_parameter Undocumented
Class Variable ​_is​_clause​_list Undocumented
Class Variable ​_is​_clone​_of Undocumented
Class Variable ​_is​_from​_clause Undocumented
Class Variable ​_is​_immutable Undocumented
Class Variable ​_is​_lambda​_element Undocumented
Class Variable ​_is​_returns​_rows Undocumented
Class Variable ​_is​_select​_container Undocumented
Class Variable ​_is​_select​_statement Undocumented
Class Variable ​_is​_singleton​_constant Undocumented
Class Variable ​_is​_text​_clause Undocumented
Class Variable ​_is​_textual Undocumented
Class Variable ​_order​_by​_label​_element Undocumented
Class Variable bind Undocumented
Class Variable description Undocumented
Class Variable is​_clause​_element Undocumented
Class Variable is​_selectable Undocumented
Class Variable stringify​_dialect Undocumented
Class Variable supports​_execution Undocumented
Instance Variable ​_propagate​_attrs like annotations, however these propagate outwards liberally as SQL constructs are built, and are set up at construction time.
Property ​_constructor return the 'constructor' for this ClauseElement.
Property entity​_namespace Undocumented

Inherited from SQLRole (via Grouping, GroupedElement, ClauseElement):

Class Variable allows​_lambda Undocumented
Class Variable uses​_inspection Undocumented

Inherited from SupportsWrappingAnnotations (via Grouping, GroupedElement, ClauseElement):

Method ​_annotate return a copy of this ClauseElement with annotations updated by the given dictionary.
Method ​_deannotate return a copy of this _expression.ClauseElement with annotations removed.
Method ​_with​_annotations return a copy of this ClauseElement with annotations replaced by the given dictionary.

Inherited from SupportsAnnotations (via Grouping, GroupedElement, ClauseElement, SupportsWrappingAnnotations):

Property ​_annotations​_cache​_key Undocumented

Inherited from MemoizedHasCacheKey (via Grouping, GroupedElement, ClauseElement):

Method ​_generate​_cache​_key return a cache key.

Inherited from HasCacheKey (via Grouping, GroupedElement, ClauseElement, MemoizedHasCacheKey):

Class Method ​_generate​_cache​_attrs generate cache key dispatcher for a new class.
Class Method ​_generate​_cache​_key​_for​_object Undocumented
Method ​_gen​_cache​_key return an optional cache key.
Class Variable __slots__ Undocumented
Class Variable ​_hierarchy​_supports​_caching private attribute which may be set to False to prevent the inherit_cache warning from being emitted for a hierarchy of subclasses.
Class Variable ​_is​_has​_cache​_key Undocumented

Inherited from HasCopyInternals (via Grouping, GroupedElement, ClauseElement):

Method ​_copy​_internals Reassign internal elements to be clones of themselves.

Inherited from Traversible (via Grouping, GroupedElement, ClauseElement):

Method get​_children Return immediate child .visitors.Traversible elements of this .visitors.Traversible.
Method __class​_getitem__ Undocumented

Inherited from ColumnElement (via Grouping):

Method cast Produce a type cast, i.e. CAST(<expression> AS <type>).
Method label Produce a column label, i.e. <columnname> AS <name>.
Method operate Operate on an argument.
Method reverse​_operate Reverse operate on an argument.
Method shares​_lineage Return True if the given _expression.ColumnElement has a common ancestor to this _expression.ColumnElement.
Class Variable foreign​_keys Undocumented
Class Variable key The 'key' that in some circumstances refers to this object in a Python namespace.
Class Variable primary​_key Undocumented
Method ​_anon​_label Undocumented
Method ​_bind​_param Undocumented
Method ​_compare​_name​_for​_result Return True if the given column element compares to this one when targeting within a result row.
Method ​_dedupe​_anon​_label​_idx label to apply to a column that is anon labeled, but repeated in the SELECT, so that we have to make an "extra anon" label that disambiguates it from the previous appearance.
Method ​_dedupe​_anon​_tq​_label​_idx Undocumented
Method ​_expression​_label a suggested label to use in the case that the column has no name, which should be used if possible as the explicit 'AS <label>' where this expression would normally have an anon label.
Method ​_make​_proxy Create a new _expression.ColumnElement representing this _expression.ColumnElement as it appears in the select list of a descending selectable.
Method ​_negate Undocumented
Method ​_proxy​_key Undocumented
Method ​_tq​_key​_label A label-based version of 'key' that in some circumstances refers to this object in a Python namespace.
Method ​_uncached​_proxy​_set An 'uncached' version of proxy set.
Method comparator Undocumented
Class Variable __visit​_name__ Undocumented
Class Variable ​_allow​_label​_resolve A flag that can be flipped to prevent a column from being resolvable by string label name.
Class Variable ​_alt​_names Undocumented
Class Variable ​_render​_label​_in​_columns​_clause No summary
Property ​_anon​_key​_label Provides a constant 'anonymous key label' for this ColumnElement.
Property ​_anon​_name​_label Provides a constant 'anonymous label' for this ColumnElement.
Property ​_anon​_tq​_key​_label Undocumented
Property ​_anon​_tq​_label Undocumented
Property ​_key​_label legacy; renamed to _tq_key_label
Property ​_label legacy; renamed to _tq_label
Property ​_non​_anon​_label the 'name' that naturally applies this element when rendered in SQL.
Property ​_select​_iterable Undocumented
Property anon​_key​_label Undocumented
Property anon​_label Undocumented
Property base​_columns Undocumented
Property expression Return a column expression.
Property proxy​_set Undocumented

Inherited from ColumnArgumentOrKeyRole (via Grouping, ColumnElement):

Class Variable ​_role​_name Undocumented

Inherited from SQLRole (via Grouping, ColumnElement, ColumnArgumentOrKeyRole, ColumnArgumentRole):

Class Variable allows​_lambda Undocumented
Class Variable uses​_inspection Undocumented

Inherited from StatementOptionRole (via Grouping, ColumnElement):

Class Variable ​_role​_name Undocumented

Inherited from SQLRole (via Grouping, ColumnElement, StatementOptionRole, StructuralRole):

Class Variable allows​_lambda Undocumented
Class Variable uses​_inspection Undocumented

Inherited from WhereHavingRole (via Grouping, ColumnElement):

Class Variable ​_role​_name Undocumented

Inherited from AllowsLambdaRole (via Grouping, ColumnElement, WhereHavingRole, OnClauseRole):

Class Variable allows​_lambda Undocumented

Inherited from SQLRole (via Grouping, ColumnElement, WhereHavingRole, OnClauseRole, StructuralRole):

Class Variable allows​_lambda Undocumented
Class Variable uses​_inspection Undocumented

Inherited from BinaryElementRole (via Grouping, ColumnElement):

Class Variable ​_role​_name Undocumented

Inherited from SQLRole (via Grouping, ColumnElement, BinaryElementRole, ExpressionElementRole):

Class Variable allows​_lambda Undocumented
Class Variable uses​_inspection Undocumented

Inherited from OrderByRole (via Grouping, ColumnElement):

Class Variable ​_role​_name Undocumented

Inherited from AllowsLambdaRole (via Grouping, ColumnElement, OrderByRole):

Class Variable allows​_lambda Undocumented

Inherited from SQLRole (via Grouping, ColumnElement, OrderByRole, ByOfRole, ColumnListRole):

Class Variable allows​_lambda Undocumented
Class Variable uses​_inspection Undocumented

Inherited from ColumnsClauseRole (via Grouping, ColumnElement):

Class Variable ​_role​_name Undocumented

Inherited from AllowsLambdaRole (via Grouping, ColumnElement, ColumnsClauseRole):

Class Variable allows​_lambda Undocumented

Inherited from UsesInspection (via Grouping, ColumnElement, ColumnsClauseRole):

Class Variable ​_post​_inspect Undocumented
Class Variable uses​_inspection Undocumented

Inherited from SQLRole (via Grouping, ColumnElement, ColumnsClauseRole, ColumnListRole):

Class Variable allows​_lambda Undocumented
Class Variable uses​_inspection Undocumented

Inherited from LimitOffsetRole (via Grouping, ColumnElement):

Class Variable ​_role​_name Undocumented

Inherited from SQLRole (via Grouping, ColumnElement, LimitOffsetRole):

Class Variable allows​_lambda Undocumented
Class Variable uses​_inspection Undocumented

Inherited from DMLColumnRole (via Grouping, ColumnElement):

Class Variable ​_role​_name Undocumented

Inherited from SQLRole (via Grouping, ColumnElement, DMLColumnRole):

Class Variable allows​_lambda Undocumented
Class Variable uses​_inspection Undocumented

Inherited from DDLConstraintColumnRole (via Grouping, ColumnElement):

Class Variable ​_role​_name Undocumented

Inherited from SQLRole (via Grouping, ColumnElement, DDLConstraintColumnRole):

Class Variable allows​_lambda Undocumented
Class Variable uses​_inspection Undocumented

Inherited from DDLExpressionRole (via Grouping, ColumnElement):

Class Variable ​_role​_name Undocumented

Inherited from SQLRole (via Grouping, ColumnElement, DDLExpressionRole, StructuralRole):

Class Variable allows​_lambda Undocumented
Class Variable uses​_inspection Undocumented

Inherited from ColumnOperators (via Grouping, ColumnElement):

Method __add__ Implement the + operator.
Method __contains__ Undocumented
Method __div__ Implement the / operator.
Method __eq__ Implement the == operator.
Method __ge__ Implement the >= operator.
Method __getitem__ Implement the [] operator.
Method __gt__ Implement the > operator.
Method __le__ Implement the <= operator.
Method __lshift__ implement the << operator.
Method __lt__ Implement the < operator.
Method __mod__ Implement the % operator.
Method __mul__ Implement the * operator.
Method __ne__ Implement the != operator.
Method __neg__ Implement the - operator.
Method __radd__ Implement the + operator in reverse.
Method __rdiv__ Implement the / operator in reverse.
Method __rmod__ Implement the % operator in reverse.
Method __rmul__ Implement the * operator in reverse.
Method __rshift__ implement the >> operator.
Method __rsub__ Implement the - operator in reverse.
Method __rtruediv__ Implement the // operator in reverse.
Method __sub__ Implement the - operator.
Method __truediv__ Implement the // operator.
Method all​_ Produce an _expression.all_ clause against the parent object.
Method any​_ Produce an _expression.any_ clause against the parent object.
Method asc Produce a _expression.asc clause against the parent object.
Method between Produce a _expression.between clause against the parent object, given the lower and upper range.
Method collate Produce a _expression.collate clause against the parent object, given the collation string.
Method concat Implement the 'concat' operator.
Method contains Implement the 'contains' operator.
Method desc Produce a _expression.desc clause against the parent object.
Method distinct Produce a _expression.distinct clause against the parent object.
Method endswith Implement the 'endswith' operator.
Method ilike Implement the ilike operator, e.g. case insensitive LIKE.
Method in​_ Implement the in operator.
Method is​_ Implement the IS operator.
Method is​_distinct​_from Implement the IS DISTINCT FROM operator.
Method is​_not Implement the IS NOT operator.
Method is​_not​_distinct​_from Implement the IS NOT DISTINCT FROM operator.
Method like Implement the like operator.
Method match Implements a database-specific 'match' operator.
Method not​_ilike implement the NOT ILIKE operator.
Method not​_in implement the NOT IN operator.
Method not​_like implement the NOT LIKE operator.
Method nulls​_first Produce a _expression.nulls_first clause against the parent object.
Method nulls​_last Produce a _expression.nulls_last clause against the parent object.
Method regexp​_match Implements a database-specific 'regexp match' operator.
Method regexp​_replace Implements a database-specific 'regexp replace' operator.
Method startswith Implement the startswith operator.
Class Variable __slots__ Undocumented
Class Variable timetuple Hack, allows datetime objects to be compared on the LHS.

Inherited from Operators (via Grouping, ColumnElement, ColumnOperators):

Method __and__ Implement the & operator.
Method __invert__ Implement the ~ operator.
Method __or__ Implement the | operator.
Method bool​_op Return a custom boolean operator.
Method op Produce a generic operator function.

Inherited from ClauseElement (via Grouping, ColumnElement):

Method compare Compare this _expression.ClauseElement to the given _expression.ClauseElement.
Method compile Compile this SQL expression.
Method params Return a copy with _expression.bindparam elements replaced.
Method unique​_params Return a copy with _expression.bindparam elements replaced.
Method __bool__ Undocumented
Method __invert__ Undocumented
Method __repr__ Undocumented
Method __str__ Undocumented
Method ​_clone Create a shallow copy of this ClauseElement.
Method ​_cloned​_set Return the set consisting all cloned ancestors of this ClauseElement.
Method ​_compile​_w​_cache Undocumented
Method ​_compiler Return a compiler appropriate for this ClauseElement, given a Dialect.
Method ​_execute​_on​_connection Undocumented
Method ​_negate​_in​_binary a hook to allow the right side of a binary expression to respond to a negation of the binary expression.
Method ​_replace​_params Undocumented
Method ​_set​_propagate​_attrs Undocumented
Method ​_ungroup Return this _expression.ClauseElement without any groupings.
Class Variable ​_cache​_key​_traversal Undocumented
Class Variable ​_is​_bind​_parameter Undocumented
Class Variable ​_is​_clause​_list Undocumented
Class Variable ​_is​_clone​_of Undocumented
Class Variable ​_is​_from​_clause Undocumented
Class Variable ​_is​_immutable Undocumented
Class Variable ​_is​_lambda​_element Undocumented
Class Variable ​_is​_returns​_rows Undocumented
Class Variable ​_is​_select​_container Undocumented
Class Variable ​_is​_select​_statement Undocumented
Class Variable ​_is​_singleton​_constant Undocumented
Class Variable ​_is​_text​_clause Undocumented
Class Variable ​_is​_textual Undocumented
Class Variable ​_order​_by​_label​_element Undocumented
Class Variable bind Undocumented
Class Variable description Undocumented
Class Variable is​_clause​_element Undocumented
Class Variable is​_selectable Undocumented
Class Variable stringify​_dialect Undocumented
Class Variable supports​_execution Undocumented
Instance Variable ​_propagate​_attrs like annotations, however these propagate outwards liberally as SQL constructs are built, and are set up at construction time.
Property ​_constructor return the 'constructor' for this ClauseElement.
Property entity​_namespace Undocumented

Inherited from SQLRole (via Grouping, ColumnElement, ClauseElement):

Class Variable allows​_lambda Undocumented
Class Variable uses​_inspection Undocumented

Inherited from SupportsWrappingAnnotations (via Grouping, ColumnElement, ClauseElement):

Method ​_annotate return a copy of this ClauseElement with annotations updated by the given dictionary.
Method ​_deannotate return a copy of this _expression.ClauseElement with annotations removed.
Method ​_with​_annotations return a copy of this ClauseElement with annotations replaced by the given dictionary.

Inherited from SupportsAnnotations (via Grouping, ColumnElement, ClauseElement, SupportsWrappingAnnotations):

Property ​_annotations​_cache​_key Undocumented

Inherited from MemoizedHasCacheKey (via Grouping, ColumnElement, ClauseElement):

Method ​_generate​_cache​_key return a cache key.

Inherited from HasCacheKey (via Grouping, ColumnElement, ClauseElement, MemoizedHasCacheKey):

Class Method ​_generate​_cache​_attrs generate cache key dispatcher for a new class.
Class Method ​_generate​_cache​_key​_for​_object Undocumented
Method ​_gen​_cache​_key return an optional cache key.
Class Variable __slots__ Undocumented
Class Variable ​_hierarchy​_supports​_caching private attribute which may be set to False to prevent the inherit_cache warning from being emitted for a hierarchy of subclasses.
Class Variable ​_is​_has​_cache​_key Undocumented

Inherited from HasCopyInternals (via Grouping, ColumnElement, ClauseElement):

Method ​_copy​_internals Reassign internal elements to be clones of themselves.

Inherited from Traversible (via Grouping, ColumnElement, ClauseElement):

Method get​_children Return immediate child .visitors.Traversible elements of this .visitors.Traversible.
Method __class​_getitem__ Undocumented
def __init__(self, element):
@_generative
def correlate(self, *fromclauses):

Return a new _expression.ScalarSelect which will correlate the given FROM clauses to that of an enclosing _expression.Select.

This method is mirrored from the _sql.Select.correlate method of the underlying _sql.Select. The method applies the _sql.Select.correlate` method, then returns a new _sql.ScalarSelect against that statement.

New in version 1.4: Previously, the _sql.ScalarSelect.correlate method was only available from _sql.Select.

See Also

_expression.ScalarSelect.correlate_except

:ref:`tutorial_scalar_subquery` - in the 2.0 tutorial

:ref:`correlated_subqueries` - in the 1.x tutorial

Parameters
*fromclausesa list of one or more _expression.FromClause constructs, or other compatible constructs (i.e. ORM-mapped classes) to become part of the correlate collection.
@_generative
def correlate_except(self, *fromclauses):

Return a new _expression.ScalarSelect which will omit the given FROM clauses from the auto-correlation process.

This method is mirrored from the _sql.Select.correlate_except method of the underlying _sql.Select. The method applies the _sql.Select.correlate_except` method, then returns a new _sql.ScalarSelect against that statement.

New in version 1.4: Previously, the _sql.ScalarSelect.correlate_except method was only available from _sql.Select.

See Also

_expression.ScalarSelect.correlate

:ref:`tutorial_scalar_subquery` - in the 2.0 tutorial

:ref:`correlated_subqueries` - in the 1.x tutorial

Parameters
*fromclausesa list of one or more _expression.FromClause constructs, or other compatible constructs (i.e. ORM-mapped classes) to become part of the correlate-exception collection.
def self_group(self, **kwargs):

Apply a 'grouping' to this _expression.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 _expression.select constructs when placed into the FROM clause of another _expression.select. (Note that subqueries should be normally created using the _expression.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 _expression.ClauseElement just returns self.

@_generative
def where(self, crit):
Apply a WHERE clause to the SELECT statement referred to by this _expression.ScalarSelect.
_from_objects: list =
_is_from_container: bool =
_is_implicitly_boolean: bool =
inherit_cache: bool =

Indicate if this .HasCacheKey instance should make use of the cache key generation scheme used by its immediate superclass.

The attribute defaults to None, which indicates that a construct has not yet taken into account whether or not its appropriate for it to participate in caching; this is functionally equivalent to setting the value to False, except that a warning is also emitted.

This flag can be set to True on a particular class, if the SQL that corresponds to the object does not change based on attributes which are local to this class, and not its superclass.

See Also

:ref:`compilerext_caching` - General guideslines for setting the .HasCacheKey.inherit_cache attribute for third-party or user defined SQL constructs.

element =
type =

Undocumented

@property
columns =

Undocumented