1241
1241
for f in self.foreign_keys]
1242
1242
if name is None and self.name is None:
1243
1243
raise exc.InvalidRequestError("Cannot initialize a sub-selectable"
1244
" with this Column object until it's 'name' has "
1244
" with this Column object until its 'name' has "
1245
1245
"been assigned.")
1247
1247
c = self._constructor(
1836
1836
def _maybe_wrap_callable(self, fn):
1837
1837
"""Wrap callables that don't accept a context.
1839
This is to allow easy compatiblity with default callables
1839
This is to allow easy compatibility with default callables
1840
1840
that aren't specific to accepting of a context.
2725
2726
Index("some_index", sometable.c.name, sometable.c.address)
2727
Functional indexes are supported as well, keeping in mind that at least
2728
one :class:`.Column` must be present::
2728
Functional indexes are supported as well, typically by using the
2729
:data:`.func` construct in conjunction with table-bound
2730
:class:`.Column` objects::
2730
2732
Index("some_index", func.lower(sometable.c.name))
2732
2734
.. versionadded:: 0.8 support for functional and expression-based indexes.
2736
An :class:`.Index` can also be manually associated with a :class:`.Table`,
2737
either through inline declaration or using :meth:`.Table.append_constraint`.
2738
When this approach is used, the names of the indexed columns can be specified
2741
Table("sometable", metadata,
2742
Column("name", String(50)),
2743
Column("address", String(100)),
2744
Index("some_index", "name", "address")
2747
To support functional or expression-based indexes in this form, the
2748
:func:`.text` construct may be used::
2750
from sqlalchemy import text
2752
Table("sometable", metadata,
2753
Column("name", String(50)),
2754
Column("address", String(100)),
2755
Index("some_index", text("lower(name)"))
2758
.. versionadded:: 0.9.5 the :func:`.text` construct may be used to
2759
specify :class:`.Index` expressions, provided the :class:`.Index`
2760
is explicitly associated with the :class:`.Table`.
2736
2765
:ref:`schema_indexes` - General information on :class:`.Index`.
2757
2786
:param \*expressions:
2758
2787
Column expressions to include in the index. The expressions
2759
2788
are normally instances of :class:`.Column`, but may also
2760
be arbitrary SQL expressions which ultmately refer to a
2789
be arbitrary SQL expressions which ultimately refer to a
2761
2790
:class:`.Column`.
2763
2792
:param unique=False:
2785
2814
visitors.traverse(expr, {}, {'column': cols.append})
2787
2816
columns.append(cols[0])
2789
columns.append(expr)
2791
2818
self.expressions = expressions
2792
2819
self.name = quoted_name(name, kw.pop("quote", None))
2798
2825
ColumnCollectionMixin.__init__(self, *columns)
2802
2828
def _set_parent(self, table):
2803
2829
ColumnCollectionMixin._set_parent(self, table)
2823
2849
self.expressions = [
2824
2850
expr if isinstance(expr, ClauseElement)
2826
for expr, colexpr in zip(self.expressions, self.columns)
2852
for expr, colexpr in util.zip_longest(self.expressions, self.columns)
2948
2974
The values associated with each "constraint class" or "constraint
2949
2975
mnemonic" key are string naming templates, such as
2950
2976
``"uq_%(table_name)s_%(column_0_name)s"``,
2951
which decribe how the name should be composed. The values associated
2977
which describe how the name should be composed. The values associated
2952
2978
with user-defined "token" keys should be callables of the form
2953
2979
``fn(constraint, table)``, which accepts the constraint/index
2954
2980
object and :class:`.Table` as arguments, returning a string