desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Remove and return an item from the queue without blocking.
Only get an item if one is immediately available. Otherwise
raise the ``Empty`` exception.'
| def get_nowait(self):
| return self.get(False)
|
'Return a list of string key names for this :class:`.KeyedTuple`.
.. seealso::
:attr:`.KeyedTuple._fields`'
| def keys(self):
| return [l for l in self._labels if (l is not None)]
|
'Return a tuple of string key names for this :class:`.KeyedTuple`.
This method provides compatibility with ``collections.namedtuple()``.
.. versionadded:: 0.8
.. seealso::
:meth:`.KeyedTuple.keys`'
| @property
def _fields(self):
| return tuple(self.keys())
|
'Return the contents of this :class:`.KeyedTuple` as a dictionary.
This method provides compatibility with ``collections.namedtuple()``,
with the exception that the dictionary returned is **not** ordered.
.. versionadded:: 0.8'
| def _asdict(self):
| return dict(((key, self.__dict__[key]) for key in self.keys()))
|
'Return an immutable proxy for this :class:`.Properties`.'
| def as_immutable(self):
| return ImmutableProperties(self._data)
|
'Construct a new :class:`.ScopedRegistry`.
:param createfunc: A creation function that will generate
a new value for the current scope, if none is present.
:param scopefunc: A function that returns a hashable
token representing the current scope (such as, current
thread identifier).'
| def __init__(self, createfunc, scopefunc):
| self.createfunc = createfunc
self.scopefunc = scopefunc
self.registry = {}
|
'Return True if an object is present in the current scope.'
| def has(self):
| return (self.scopefunc() in self.registry)
|
'Set the value forthe current scope.'
| def set(self, obj):
| self.registry[self.scopefunc()] = obj
|
'Clear the current scope, if any.'
| def clear(self):
| try:
del self.registry[self.scopefunc()]
except KeyError:
pass
|
'Expire all memoized properties for *instance*.'
| def expire_instance(self, instance):
| stash = instance.__dict__
for attribute in self.attributes:
stash.pop(attribute, None)
|
'Construct a new named symbol.'
| def __new__(self, name, doc=None, canonical=None):
| assert isinstance(name, compat.string_types)
if (canonical is None):
canonical = hash(name)
v = int.__new__(_symbol, canonical)
v.name = name
if doc:
v.__doc__ = doc
return v
|
'Create a string-holding type.
:param length: optional, a length for the column for use in
DDL and CAST expressions. May be safely omitted if no ``CREATE
TABLE`` will be issued. Certain databases may require a
``length`` for use in DDL, and will raise an exception when
the ``CREATE TABLE`` DDL is issued if a ``VARCHA... | def __init__(self, length=None, collation=None, convert_unicode=False, unicode_error=None, _warn_on_bytestring=False):
| if ((unicode_error is not None) and (convert_unicode != 'force')):
raise exc.ArgumentError("convert_unicode must be 'force' when unicode_error is set.")
self.length = length
self.collation = collation
self.convert_unicode = convert_unicode
self.unicode_error = unicode_er... |
'Create a :class:`.Unicode` object.
Parameters are the same as that of :class:`.String`,
with the exception that ``convert_unicode``
defaults to ``True``.'
| def __init__(self, length=None, **kwargs):
| kwargs.setdefault('convert_unicode', True)
kwargs.setdefault('_warn_on_bytestring', True)
super(Unicode, self).__init__(length=length, **kwargs)
|
'Create a Unicode-converting Text type.
Parameters are the same as that of :class:`.Text`,
with the exception that ``convert_unicode``
defaults to ``True``.'
| def __init__(self, length=None, **kwargs):
| kwargs.setdefault('convert_unicode', True)
kwargs.setdefault('_warn_on_bytestring', True)
super(UnicodeText, self).__init__(length=length, **kwargs)
|
'Construct a Numeric.
:param precision: the numeric precision for use in DDL ``CREATE
TABLE``.
:param scale: the numeric scale for use in DDL ``CREATE TABLE``.
:param asdecimal: default True. Return whether or not
values should be sent as Python Decimal objects, or
as floats. Different DBAPIs send one or the other b... | def __init__(self, precision=None, scale=None, decimal_return_scale=None, asdecimal=True):
| self.precision = precision
self.scale = scale
self.decimal_return_scale = decimal_return_scale
self.asdecimal = asdecimal
|
'Construct a Float.
:param precision: the numeric precision for use in DDL ``CREATE
TABLE``.
:param asdecimal: the same flag as that of :class:`.Numeric`, but
defaults to ``False``. Note that setting this flag to ``True``
results in floating point conversion.
:param decimal_return_scale: Default scale to use when con... | def __init__(self, precision=None, asdecimal=False, decimal_return_scale=None, **kwargs):
| self.precision = precision
self.asdecimal = asdecimal
self.decimal_return_scale = decimal_return_scale
if kwargs:
util.warn_deprecated('Additional keyword arguments passed to Float ignored.')
|
'Construct a new :class:`.DateTime`.
:param timezone: boolean. If True, and supported by the
backend, will produce \'TIMESTAMP WITH TIMEZONE\'. For backends
that don\'t support timezone aware timestamps, has no
effect.'
| def __init__(self, timezone=False):
| self.timezone = timezone
|
'See :meth:`.TypeEngine.coerce_compared_value` for a description.'
| def coerce_compared_value(self, op, value):
| if isinstance(value, util.string_types):
return self
else:
return super(_Binary, self).coerce_compared_value(op, value)
|
'Construct a LargeBinary type.
:param length: optional, a length for the column for use in
DDL statements, for those BLOB types that accept a length
(i.e. MySQL). It does *not* produce a small BINARY/VARBINARY
type - use the BINARY/VARBINARY types specifically for those.
May be safely omitted if no ``CREATE
TABLE`` wi... | def __init__(self, length=None):
| _Binary.__init__(self, length=length)
|
'Issue CREATE ddl for this type, if applicable.'
| def create(self, bind=None, checkfirst=False):
| if (bind is None):
bind = _bind_or_error(self)
t = self.dialect_impl(bind.dialect)
if ((t.__class__ is not self.__class__) and isinstance(t, SchemaType)):
t.create(bind=bind, checkfirst=checkfirst)
|
'Issue DROP ddl for this type, if applicable.'
| def drop(self, bind=None, checkfirst=False):
| if (bind is None):
bind = _bind_or_error(self)
t = self.dialect_impl(bind.dialect)
if ((t.__class__ is not self.__class__) and isinstance(t, SchemaType)):
t.drop(bind=bind, checkfirst=checkfirst)
|
'Construct an enum.
Keyword arguments which don\'t apply to a specific backend are ignored
by that backend.
:param \*enums: string or unicode enumeration labels. If unicode
labels are present, the `convert_unicode` flag is auto-enabled.
:param convert_unicode: Enable unicode-aware bind parameter and
result-set processi... | def __init__(self, *enums, **kw):
| self.enums = enums
self.native_enum = kw.pop('native_enum', True)
convert_unicode = kw.pop('convert_unicode', None)
if (convert_unicode is None):
for e in enums:
if isinstance(e, util.text_type):
convert_unicode = True
break
else:
c... |
'Construct a PickleType.
:param protocol: defaults to ``pickle.HIGHEST_PROTOCOL``.
:param pickler: defaults to cPickle.pickle or pickle.pickle if
cPickle is not available. May be any object with
pickle-compatible ``dumps` and ``loads`` methods.
:param comparator: a 2-arg callable predicate used
to compare values of th... | def __init__(self, protocol=pickle.HIGHEST_PROTOCOL, pickler=None, comparator=None):
| self.protocol = protocol
self.pickler = (pickler or pickle)
self.comparator = comparator
super(PickleType, self).__init__()
|
'Construct a Boolean.
:param create_constraint: defaults to True. If the boolean
is generated as an int/smallint, also create a CHECK constraint
on the table that ensures 1 or 0 as a value.
:param name: if a CHECK constraint is generated, specify
the name of the constraint.'
| def __init__(self, create_constraint=True, name=None):
| self.create_constraint = create_constraint
self.name = name
|
'Construct an Interval object.
:param native: when True, use the actual
INTERVAL type provided by the database, if
supported (currently Postgresql, Oracle).
Otherwise, represent the interval data as
an epoch value regardless.
:param second_precision: For native interval types
which support a "fractional seconds precisi... | def __init__(self, native=True, second_precision=None, day_precision=None):
| super(Interval, self).__init__()
self.native = native
self.second_precision = second_precision
self.day_precision = day_precision
|
'See :meth:`.TypeEngine.coerce_compared_value` for a description.'
| def coerce_compared_value(self, op, value):
| return self.impl.coerce_compared_value(op, value)
|
'return a SELECT COUNT generated against this
:class:`.FromClause`.'
| @util.dependencies('sqlalchemy.sql.functions')
def count(self, functions, whereclause=None, **params):
| if self.primary_key:
col = list(self.primary_key)[0]
else:
col = list(self.columns)[0]
return Select([functions.func.count(col).label('tbl_row_count')], whereclause, from_obj=[self], **params)
|
'return a SELECT of this :class:`.FromClause`.
.. seealso::
:func:`~.sql.expression.select` - general purpose
method which allows for arbitrary column lists.'
| def select(self, whereclause=None, **params):
| return Select([self], whereclause, **params)
|
'Return a :class:`.Join` from this :class:`.FromClause`
to another :class:`FromClause`.
E.g.::
from sqlalchemy import join
j = user_table.join(address_table,
user_table.c.id == address_table.c.user_id)
stmt = select([user_table]).select_from(j)
would emit SQL along the lines of::
SELECT user.id, user.name FROM user
JOI... | def join(self, right, onclause=None, isouter=False):
| return Join(self, right, onclause, isouter)
|
'Return a :class:`.Join` from this :class:`.FromClause`
to another :class:`FromClause`, with the "isouter" flag set to
True.
E.g.::
from sqlalchemy import outerjoin
j = user_table.outerjoin(address_table,
user_table.c.id == address_table.c.user_id)
The above is equivalent to::
j = user_table.join(address_table,
user_ta... | def outerjoin(self, right, onclause=None):
| return Join(self, right, onclause, True)
|
'return an alias of this :class:`.FromClause`.
This is shorthand for calling::
from sqlalchemy import alias
a = alias(self, name=name)
See :func:`~.expression.alias` for details.'
| def alias(self, name=None, flat=False):
| return Alias(self, name)
|
'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.'
| def is_derived_from(self, fromclause):
| return (fromclause in self._cloned_set)
|
'Return True if this FromClause and the other represent
the same lexical identity.
This tests if either one is a copy of the other, or
if they are the same via annotation identity.'
| def _is_lexical_equivalent(self, other):
| return self._cloned_set.intersection(other._cloned_set)
|
'replace all occurrences of FromClause \'old\' with the given Alias
object, returning a copy of this :class:`.FromClause`.'
| @util.dependencies('sqlalchemy.sql.util')
def replace_selectable(self, sqlutil, old, alias):
| return sqlutil.ClauseAdapter(alias).traverse(self)
|
'Return corresponding_column for the given column, or if None
search for a match in the given dictionary.'
| def correspond_on_equivalents(self, column, equivalents):
| col = self.corresponding_column(column, require_embedded=True)
if ((col is None) and (col in equivalents)):
for equiv in equivalents[col]:
nc = self.corresponding_column(equiv, require_embedded=True)
if nc:
return nc
return col
|
'Given a :class:`.ColumnElement`, return the exported
:class:`.ColumnElement` object from this :class:`.Selectable`
which corresponds to that original
:class:`~sqlalchemy.schema.Column` via a common ancestor
column.
:param column: the target :class:`.ColumnElement` to be matched
:param require_embedded: only return cor... | def corresponding_column(self, column, require_embedded=False):
| def embedded(expanded_proxy_set, target_set):
for t in target_set.difference(expanded_proxy_set):
if (not set(_expand_cloned([t])).intersection(expanded_proxy_set)):
return False
return True
if self.c.contains_column(column):
return column
(col, intersect)... |
'a brief description of this FromClause.
Used primarily for error message formatting.'
| @property
def description(self):
| return getattr(self, 'name', (self.__class__.__name__ + ' object'))
|
'delete memoized collections when a FromClause is cloned.'
| def _reset_exported(self):
| self._memoized_property.expire_instance(self)
|
'A named-based collection of :class:`.ColumnElement` objects
maintained by this :class:`.FromClause`.
The :attr:`.columns`, or :attr:`.c` collection, is the gateway
to the construction of SQL expressions using table-bound or
other selectable-bound columns::
select([mytable]).where(mytable.c.somecolumn == 5)'
| @_memoized_property
def columns(self):
| if ('_columns' not in self.__dict__):
self._init_collections()
self._populate_column_collection()
return self._columns.as_immutable()
|
'Return the collection of Column objects which comprise the
primary key of this FromClause.'
| @_memoized_property
def primary_key(self):
| self._init_collections()
self._populate_column_collection()
return self.primary_key
|
'Return the collection of ForeignKey objects which this
FromClause references.'
| @_memoized_property
def foreign_keys(self):
| self._init_collections()
self._populate_column_collection()
return self.foreign_keys
|
'Given a column added to the .c collection of an underlying
selectable, produce the local version of that column, assuming this
selectable ultimately should proxy this column.
this is used to "ping" a derived selectable to add a new column
to its .c. collection when a Column has been added to one of the
Table objects i... | def _refresh_for_new_column(self, column):
| if (not self._cols_populated):
return None
elif ((column.key in self.columns) and (self.columns[column.key] is column)):
return column
else:
return None
|
'Construct a new :class:`.Join`.
The usual entrypoint here is the :func:`~.expression.join`
function or the :meth:`.FromClause.join` method of any
:class:`.FromClause` object.'
| def __init__(self, left, right, onclause=None, isouter=False):
| self.left = _interpret_as_from(left)
self.right = _interpret_as_from(right).self_group()
if (onclause is None):
self.onclause = self._match_primaries(self.left, self.right)
else:
self.onclause = onclause
self.isouter = isouter
|
'Return an ``OUTER JOIN`` clause element.
The returned object is an instance of :class:`.Join`.
Similar functionality is also available via the
:meth:`~.FromClause.outerjoin()` method on any
:class:`.FromClause`.
:param left: The left side of the join.
:param right: The right side of the join.
:param onclause: Optiona... | @classmethod
def _create_outerjoin(cls, left, right, onclause=None):
| return cls(left, right, onclause, isouter=True)
|
'Produce a :class:`.Join` object, given two :class:`.FromClause`
expressions.
E.g.::
j = join(user_table, address_table, user_table.c.id == address_table.c.user_id)
stmt = select([user_table]).select_from(j)
would emit SQL along the lines of::
SELECT user.id, user.name FROM user
JOIN address ON user.id = address.user_i... | @classmethod
def _create_join(cls, left, right, onclause=None, isouter=False):
| return cls(left, right, onclause, isouter)
|
'create a join condition between two tables or selectables.
e.g.::
join_condition(tablea, tableb)
would produce an expression along the lines of::
tablea.c.id==tableb.c.tablea_id
The join is determined based on the foreign key relationships
between the two selectables. If there are multiple ways
to join, or no way to... | @classmethod
def _join_condition(cls, a, b, ignore_nonexistent_tables=False, a_subset=None, consider_as_foreign_keys=None):
| constraints = collections.defaultdict(list)
for left in (a_subset, a):
if (left is None):
continue
for fk in sorted(b.foreign_keys, key=(lambda fk: fk.parent._creation_order)):
if ((consider_as_foreign_keys is not None) and (fk.parent not in consider_as_foreign_keys)):
... |
'Create a :class:`.Select` from this :class:`.Join`.
The equivalent long-hand form, given a :class:`.Join` object
``j``, is::
from sqlalchemy import select
j = select([j.left, j.right], **kw).\
where(whereclause).\
select_from(j)
:param whereclause: the WHERE criterion that will be sent to
the :func:`select()` function... | def select(self, whereclause=None, **kwargs):
| collist = [self.left, self.right]
return Select(collist, whereclause, from_obj=[self], **kwargs)
|
'return an alias of this :class:`.Join`.
The default behavior here is to first produce a SELECT
construct from this :class:`.Join`, then to produce a
:class:`.Alias` from that. So given a join of the form::
j = table_a.join(table_b, table_a.c.id == table_b.c.a_id)
The JOIN by itself would look like::
table_a JOIN tabl... | @util.dependencies('sqlalchemy.sql.util')
def alias(self, sqlutil, name=None, flat=False):
| if flat:
assert (name is None), "Can't send name argument with flat"
(left_a, right_a) = (self.left.alias(flat=True), self.right.alias(flat=True))
adapter = sqlutil.ClauseAdapter(left_a).chain(sqlutil.ClauseAdapter(right_a))
return left_a.join(right_a, adapter.traverse... |
'Produce a new :class:`.TableClause`.
The object returned is an instance of :class:`.TableClause`, which
represents the "syntactical" portion of the schema-level
:class:`~.schema.Table` object.
It may be used to construct lightweight table constructs.
Note that the :func:`.expression.table` function is not part of
the ... | def __init__(self, name, *columns):
| super(TableClause, self).__init__()
self.name = self.fullname = name
self._columns = ColumnCollection()
self.primary_key = ColumnSet()
self.foreign_keys = set()
for c in columns:
self.append_column(c)
|
'return a SELECT COUNT generated against this
:class:`.TableClause`.'
| @util.dependencies('sqlalchemy.sql.functions')
def count(self, functions, whereclause=None, **params):
| if self.primary_key:
col = list(self.primary_key)[0]
else:
col = list(self.columns)[0]
return Select([functions.func.count(col).label('tbl_row_count')], whereclause, from_obj=[self], **params)
|
'Generate an :func:`.insert` construct against this
:class:`.TableClause`.
E.g.::
table.insert().values(name=\'foo\')
See :func:`.insert` for argument and usage information.'
| @util.dependencies('sqlalchemy.sql.dml')
def insert(self, dml, values=None, inline=False, **kwargs):
| return dml.Insert(self, values=values, inline=inline, **kwargs)
|
'Generate an :func:`.update` construct against this
:class:`.TableClause`.
E.g.::
table.update().where(table.c.id==7).values(name=\'foo\')
See :func:`.update` for argument and usage information.'
| @util.dependencies('sqlalchemy.sql.dml')
def update(self, dml, whereclause=None, values=None, inline=False, **kwargs):
| return dml.Update(self, whereclause=whereclause, values=values, inline=inline, **kwargs)
|
'Generate a :func:`.delete` construct against this
:class:`.TableClause`.
E.g.::
table.delete().where(table.c.id==7)
See :func:`.delete` for argument and usage information.'
| @util.dependencies('sqlalchemy.sql.dml')
def delete(self, dml, whereclause=None, **kwargs):
| return dml.Delete(self, whereclause, **kwargs)
|
'Parse the for_update arugment of :func:`.select`.
:param mode: Defines the lockmode to use.
``None`` - translates to no lockmode
``\'update\'`` - translates to ``FOR UPDATE``
(standard SQL, supported by most dialects)
``\'nowait\'`` - translates to ``FOR UPDATE NOWAIT``
(supported by Oracle, PostgreSQL 8.1 upwards)
``... | @classmethod
def parse_legacy_select(self, arg):
| if (arg in (None, False)):
return None
nowait = read = False
if (arg == 'nowait'):
nowait = True
elif (arg == 'read'):
read = True
elif (arg == 'read_nowait'):
read = nowait = True
elif (arg is not True):
raise exc.ArgumentError(('Unknown for_update ... |
'Represents arguments specified to :meth:`.Select.for_update`.
.. versionadded:: 0.9.0'
| def __init__(self, nowait=False, read=False, of=None):
| self.nowait = nowait
self.read = read
if (of is not None):
self.of = [_interpret_as_column_or_from(elem) for elem in util.to_list(of)]
else:
self.of = None
|
'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
:class:`ScalarSelect`.'
| def as_scalar(self):
| return ScalarSelect(self)
|
'return a \'scalar\' representation of this selectable, embedded as a
subquery with a label.
.. seealso::
:meth:`~.SelectBase.as_scalar`.'
| def label(self, name):
| return self.as_scalar().label(name)
|
'Return a new :class:`.CTE`, or Common Table Expression instance.
Common table expressions are a SQL standard whereby SELECT
statements can draw upon secondary statements specified along
with the primary statement, using a clause called "WITH".
Special semantics regarding UNION can also be employed to
allow "recursive"... | def cte(self, name=None, recursive=False):
| return CTE(self, name=name, recursive=recursive)
|
'return a new selectable with the \'autocommit\' flag set to
True.'
| @_generative
@util.deprecated('0.6', message="``autocommit()`` is deprecated. Use :meth:`.Executable.execution_options` with the 'autocommit' flag.")
def autocommit(self):
| self._execution_options = self._execution_options.union({'autocommit': True})
|
'Override the default _generate() method to also clear out
exported collections.'
| def _generate(self):
| s = self.__class__.__new__(self.__class__)
s.__dict__ = self.__dict__.copy()
s._reset_exported()
return s
|
'Provide legacy dialect support for the ``for_update`` attribute.'
| @property
def for_update(self):
| if (self._for_update_arg is not None):
return self._for_update_arg.legacy_for_update_value
else:
return None
|
'Specify a ``FOR UPDATE`` clause for this :class:`.GenerativeSelect`.
E.g.::
stmt = select([table]).with_for_update(nowait=True)
On a database like Postgresql or Oracle, the above would render a
statement like::
SELECT table.a, table.b FROM table FOR UPDATE NOWAIT
on other backends, the ``nowait`` option is ignored and... | @_generative
def with_for_update(self, nowait=False, read=False, of=None):
| self._for_update_arg = ForUpdateArg(nowait=nowait, read=read, of=of)
|
'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 regard... | @_generative
def apply_labels(self):
| self.use_labels = True
|
'return a new selectable with the given LIMIT criterion
applied.'
| @_generative
def limit(self, limit):
| self._limit = util.asint(limit)
|
'return a new selectable with the given OFFSET criterion
applied.'
| @_generative
def offset(self, offset):
| self._offset = util.asint(offset)
|
'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.'
| @_generative
def order_by(self, *clauses):
| self.append_order_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.'
| @_generative
def group_by(self, *clauses):
| self.append_group_by(*clauses)
|
'Append the given ORDER BY criterion applied to this selectable.
The criterion will be appended to any pre-existing ORDER BY criterion.
This is an **in-place** mutation method; the
:meth:`~.GenerativeSelect.order_by` method is preferred, as it provides standard
:term:`method chaining`.'
| def append_order_by(self, *clauses):
| if ((len(clauses) == 1) and (clauses[0] is None)):
self._order_by_clause = ClauseList()
else:
if (getattr(self, '_order_by_clause', None) is not None):
clauses = (list(self._order_by_clause) + list(clauses))
self._order_by_clause = ClauseList(*clauses)
|
'Append the given GROUP BY criterion applied to this selectable.
The criterion will be appended to any pre-existing GROUP BY criterion.
This is an **in-place** mutation method; the
:meth:`~.GenerativeSelect.group_by` method is preferred, as it provides standard
:term:`method chaining`.'
| def append_group_by(self, *clauses):
| if ((len(clauses) == 1) and (clauses[0] is None)):
self._group_by_clause = ClauseList()
else:
if (getattr(self, '_group_by_clause', None) is not None):
clauses = (list(self._group_by_clause) + list(clauses))
self._group_by_clause = ClauseList(*clauses)
|
'Return a ``UNION`` of multiple selectables.
The returned object is an instance of
:class:`.CompoundSelect`.
A similar :func:`union()` method is available on all
:class:`.FromClause` subclasses.
\*selects
a list of :class:`.Select` instances.
\**kwargs
available keyword arguments are the same as those of
:func:`select`... | @classmethod
def _create_union(cls, *selects, **kwargs):
| return CompoundSelect(CompoundSelect.UNION, *selects, **kwargs)
|
'Return a ``UNION ALL`` of multiple selectables.
The returned object is an instance of
:class:`.CompoundSelect`.
A similar :func:`union_all()` method is available on all
:class:`.FromClause` subclasses.
\*selects
a list of :class:`.Select` instances.
\**kwargs
available keyword arguments are the same as those of
:func:... | @classmethod
def _create_union_all(cls, *selects, **kwargs):
| return CompoundSelect(CompoundSelect.UNION_ALL, *selects, **kwargs)
|
'Return an ``EXCEPT`` of multiple selectables.
The returned object is an instance of
:class:`.CompoundSelect`.
\*selects
a list of :class:`.Select` instances.
\**kwargs
available keyword arguments are the same as those of
:func:`select`.'
| @classmethod
def _create_except(cls, *selects, **kwargs):
| return CompoundSelect(CompoundSelect.EXCEPT, *selects, **kwargs)
|
'Return an ``EXCEPT ALL`` of multiple selectables.
The returned object is an instance of
:class:`.CompoundSelect`.
\*selects
a list of :class:`.Select` instances.
\**kwargs
available keyword arguments are the same as those of
:func:`select`.'
| @classmethod
def _create_except_all(cls, *selects, **kwargs):
| return CompoundSelect(CompoundSelect.EXCEPT_ALL, *selects, **kwargs)
|
'Return an ``INTERSECT`` of multiple selectables.
The returned object is an instance of
:class:`.CompoundSelect`.
\*selects
a list of :class:`.Select` instances.
\**kwargs
available keyword arguments are the same as those of
:func:`select`.'
| @classmethod
def _create_intersect(cls, *selects, **kwargs):
| return CompoundSelect(CompoundSelect.INTERSECT, *selects, **kwargs)
|
'Return an ``INTERSECT ALL`` of multiple selectables.
The returned object is an instance of
:class:`.CompoundSelect`.
\*selects
a list of :class:`.Select` instances.
\**kwargs
available keyword arguments are the same as those of
:func:`select`.'
| @classmethod
def _create_intersect_all(cls, *selects, **kwargs):
| return CompoundSelect(CompoundSelect.INTERSECT_ALL, *selects, **kwargs)
|
'Add one or more expressions following the statement keyword, i.e.
SELECT, INSERT, UPDATE, or DELETE. Generative.
This is used to support backend-specific prefix keywords such as those
provided by MySQL.
E.g.::
stmt = table.insert().prefix_with("LOW_PRIORITY", dialect="mysql")
Multiple prefixes can be specified by mult... | @_generative
def prefix_with(self, *expr, **kw):
| dialect = kw.pop('dialect', None)
if kw:
raise exc.ArgumentError(('Unsupported argument(s): %s' % ','.join(kw)))
self._setup_prefixes(expr, dialect)
|
'Construct a new :class:`.Select`.
Similar functionality is also available via the :meth:`.FromClause.select`
method on any :class:`.FromClause`.
All arguments which accept :class:`.ClauseElement` arguments also accept
string arguments, which will be converted as appropriate into
either :func:`text()` or :func:`literal... | def __init__(self, columns=None, whereclause=None, from_obj=None, distinct=False, having=None, correlate=True, prefixes=None, **kwargs):
| self._auto_correlate = correlate
if (distinct is not False):
if (distinct is True):
self._distinct = True
else:
self._distinct = [_literal_as_text(e) for e in util.to_list(distinct)]
if (from_obj is not None):
self._from_obj = util.OrderedSet((_interpret_as_fr... |
'Return the full list of \'from\' clauses to be displayed.
Takes into account a set of existing froms which may be
rendered in the FROM clause of enclosing selects; this Select
may want to leave those absent if it is automatically
correlating.'
| def _get_display_froms(self, explicit_correlate_froms=None, implicit_correlate_froms=None):
| froms = self._froms
toremove = set(itertools.chain(*[_expand_cloned(f._hide_froms) for f in froms]))
if toremove:
if self._from_cloned:
toremove.update((self._from_cloned[f] for f in toremove.intersection(self._from_cloned) if self._from_cloned[f]._is_lexical_equivalent(f)))
from... |
'Return the displayed list of FromClause elements.'
| @property
def froms(self):
| return self._get_display_froms()
|
'Add an indexing hint for the given selectable to this
:class:`.Select`.
The text of the hint is rendered in the appropriate
location for the database backend in use, relative
to the given :class:`.Table` or :class:`.Alias` passed as the
``selectable`` argument. The dialect implementation
typically uses Python string s... | @_generative
def with_hint(self, selectable, text, dialect_name='*'):
| self._hints = self._hints.union({(selectable, dialect_name): text})
|
'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.'
| @_memoized_property.method
def locate_all_froms(self):
| froms = self._froms
return (froms + list(_from_objects(*froms)))
|
'an iterator of all ColumnElement expressions which would
be rendered into the columns clause of the resulting SELECT statement.'
| @property
def inner_columns(self):
| return _select_iterables(self._raw_columns)
|
'return child elements as per the ClauseElement specification.'
| def get_children(self, column_collections=True, **kwargs):
| return (((((column_collections and list(self.columns)) or []) + self._raw_columns) + list(self._froms)) + [x for x in (self._whereclause, self._having, self._order_by_clause, self._group_by_clause) if (x is not None)])
|
'return a new select() construct with the given column expression
added to its columns clause.'
| @_generative
def column(self, column):
| self.append_column(column)
|
'Return a new :func`.select` construct with redundantly
named, equivalently-valued columns removed from the columns clause.
"Redundant" here means two columns where one refers to the
other either based on foreign key, or via a simple equality
comparison in the WHERE clause of the statement. The primary purpose
of thi... | @util.dependencies('sqlalchemy.sql.util')
def reduce_columns(self, sqlutil, only_synonyms=True):
| return self.with_only_columns(sqlutil.reduce_columns(self.inner_columns, only_synonyms=only_synonyms, *((self._whereclause,) + tuple(self._from_obj))))
|
'Return a new :func:`.select` construct with its columns
clause replaced with the given columns.
.. versionchanged:: 0.7.3
Due to a bug fix, this method has a slight
behavioral change as of version 0.7.3.
Prior to version 0.7.3, the FROM clause of
a :func:`.select` was calculated upfront and as new columns
were added; ... | @_generative
def with_only_columns(self, columns):
| self._reset_exported()
rc = []
for c in columns:
c = _interpret_as_column_or_from(c)
if isinstance(c, ScalarSelect):
c = c.self_group(against=operators.comma_op)
rc.append(c)
self._raw_columns = rc
|
'return a new select() construct with the given expression added to
its WHERE clause, joined to the existing clause via AND, if any.'
| @_generative
def where(self, whereclause):
| self.append_whereclause(whereclause)
|
'return a new select() construct with the given expression added to
its HAVING clause, joined to the existing clause via AND, if any.'
| @_generative
def having(self, having):
| self.append_having(having)
|
'Return a new select() construct which will apply DISTINCT to its
columns clause.
:param \*expr: optional column expressions. When present,
the Postgresql dialect will render a ``DISTINCT ON (<expressions>>)``
construct.'
| @_generative
def distinct(self, *expr):
| if expr:
expr = [_literal_as_text(e) for e in expr]
if isinstance(self._distinct, list):
self._distinct = (self._distinct + expr)
else:
self._distinct = expr
else:
self._distinct = True
|
'return a new :func:`.select` construct with the
given FROM expression
merged into its list of FROM objects.
E.g.::
table1 = table(\'t1\', column(\'a\'))
table2 = table(\'t2\', column(\'b\'))
s = select([table1.c.a]).\
select_from(
table1.join(table2, table1.c.a==table2.c.b)
The "from" list is a unique set on the ident... | @_generative
def select_from(self, fromclause):
| self.append_from(fromclause)
|
'return a new :class:`.Select` which will correlate the given FROM
clauses to that of an enclosing :class:`.Select`.
Calling this method turns off the :class:`.Select` object\'s
default behavior of "auto-correlation". Normally, FROM elements
which appear in a :class:`.Select` that encloses this one via
its :term:`WHER... | @_generative
def correlate(self, *fromclauses):
| self._auto_correlate = False
if (fromclauses and (fromclauses[0] is None)):
self._correlate = ()
else:
self._correlate = set(self._correlate).union((_interpret_as_from(f) for f in fromclauses))
|
'return a new :class:`.Select` which will omit the given FROM
clauses from the auto-correlation process.
Calling :meth:`.Select.correlate_except` turns off the
:class:`.Select` object\'s default behavior of
"auto-correlation" for the given FROM elements. An element
specified here will unconditionally appear in the FRO... | @_generative
def correlate_except(self, *fromclauses):
| self._auto_correlate = False
if (fromclauses and (fromclauses[0] is None)):
self._correlate_except = ()
else:
self._correlate_except = set((self._correlate_except or ())).union((_interpret_as_from(f) for f in fromclauses))
|
'append the given correlation expression to this select()
construct.
This is an **in-place** mutation method; the
:meth:`~.Select.correlate` method is preferred, as it provides standard
:term:`method chaining`.'
| def append_correlation(self, fromclause):
| self._auto_correlate = False
self._correlate = set(self._correlate).union((_interpret_as_from(f) for f in fromclause))
|
'append the given column expression to the columns clause of this
select() construct.
This is an **in-place** mutation method; the
:meth:`~.Select.column` method is preferred, as it provides standard
:term:`method chaining`.'
| def append_column(self, column):
| self._reset_exported()
column = _interpret_as_column_or_from(column)
if isinstance(column, ScalarSelect):
column = column.self_group(against=operators.comma_op)
self._raw_columns = (self._raw_columns + [column])
|
'append the given columns clause prefix expression to this select()
construct.
This is an **in-place** mutation method; the
:meth:`~.Select.prefix_with` method is preferred, as it provides standard
:term:`method chaining`.'
| def append_prefix(self, clause):
| clause = _literal_as_text(clause)
self._prefixes = (self._prefixes + (clause,))
|
'append the given expression to this select() construct\'s WHERE
criterion.
The expression will be joined to existing WHERE criterion via AND.
This is an **in-place** mutation method; the
:meth:`~.Select.where` method is preferred, as it provides standard
:term:`method chaining`.'
| def append_whereclause(self, whereclause):
| self._reset_exported()
self._whereclause = and_(True_._ifnone(self._whereclause), whereclause)
|
'append the given expression to this select() construct\'s HAVING
criterion.
The expression will be joined to existing HAVING criterion via AND.
This is an **in-place** mutation method; the
:meth:`~.Select.having` method is preferred, as it provides standard
:term:`method chaining`.'
| def append_having(self, having):
| self._reset_exported()
self._having = and_(True_._ifnone(self._having), having)
|
'append the given FromClause expression to this select() construct\'s
FROM clause.
This is an **in-place** mutation method; the
:meth:`~.Select.select_from` method is preferred, as it provides standard
:term:`method chaining`.'
| def append_from(self, fromclause):
| self._reset_exported()
fromclause = _interpret_as_from(fromclause)
self._from_obj = self._from_obj.union([fromclause])
|
'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 and should not require explicit use.'
| def self_group(self, against=None):
| if isinstance(against, CompoundSelect):
return self
return FromGrouping(self)
|
'return a SQL UNION of this select() construct against the given
selectable.'
| def union(self, other, **kwargs):
| return CompoundSelect._create_union(self, other, **kwargs)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.