summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/schema.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2020-04-14 13:15:21 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2020-04-14 13:15:21 -0400
commitcea03be855514d592b6671fa6dbc074a19a795fb (patch)
treef127540bda77a4ea5d9935cffedf04d8b01776a9 /lib/sqlalchemy/sql/schema.py
parenta898ade3bc36ca27cf9475d1348249646eb40e95 (diff)
downloadsqlalchemy-cea03be855514d592b6671fa6dbc074a19a795fb.tar.gz
Run search and replace of symbolic module names
Replaces a wide array of Sphinx-relative doc references with an abbreviated absolute form now supported by zzzeeksphinx. Change-Id: I94bffcc3f37885ffdde6238767224296339698a2
Diffstat (limited to 'lib/sqlalchemy/sql/schema.py')
-rw-r--r--lib/sqlalchemy/sql/schema.py721
1 files changed, 424 insertions, 297 deletions
diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py
index ac3fb9607..ec8d5a458 100644
--- a/lib/sqlalchemy/sql/schema.py
+++ b/lib/sqlalchemy/sql/schema.py
@@ -60,9 +60,9 @@ RETAIN_SCHEMA = util.symbol("retain_schema")
BLANK_SCHEMA = util.symbol(
"blank_schema",
- """Symbol indicating that a :class:`.Table` or :class:`.Sequence`
+ """Symbol indicating that a :class:`_schema.Table` or :class:`.Sequence`
should have 'None' for its schema, even if the parent
- :class:`.MetaData` has specified a schema.
+ :class:`_schema.MetaData` has specified a schema.
.. versionadded:: 1.0.14
@@ -131,7 +131,7 @@ class SchemaItem(SchemaEventTarget, visitors.Visitable):
The dictionary is automatically generated when first accessed.
It can also be specified in the constructor of some objects,
- such as :class:`.Table` and :class:`.Column`.
+ such as :class:`_schema.Table` and :class:`_schema.Column`.
"""
return {}
@@ -155,12 +155,14 @@ class Table(DialectKWArgs, SchemaItem, TableClause):
Column('value', String(50))
)
- The :class:`.Table` object constructs a unique instance of itself based
+ The :class:`_schema.Table`
+ object constructs a unique instance of itself based
on its name and optional schema name within the given
- :class:`.MetaData` object. Calling the :class:`.Table`
- constructor with the same name and same :class:`.MetaData` argument
- a second time will return the *same* :class:`.Table` object - in this way
- the :class:`.Table` constructor acts as a registry function.
+ :class:`_schema.MetaData` object. Calling the :class:`_schema.Table`
+ constructor with the same name and same :class:`_schema.MetaData` argument
+ a second time will return the *same* :class:`_schema.Table`
+ object - in this way
+ the :class:`_schema.Table` constructor acts as a registry function.
.. seealso::
@@ -171,10 +173,12 @@ class Table(DialectKWArgs, SchemaItem, TableClause):
:param name: The name of this table as represented in the database.
The table name, along with the value of the ``schema`` parameter,
- forms a key which uniquely identifies this :class:`.Table` within
- the owning :class:`.MetaData` collection.
- Additional calls to :class:`.Table` with the same name, metadata,
- and schema name will return the same :class:`.Table` object.
+ forms a key which uniquely identifies this :class:`_schema.Table`
+ within
+ the owning :class:`_schema.MetaData` collection.
+ Additional calls to :class:`_schema.Table` with the same name,
+ metadata,
+ and schema name will return the same :class:`_schema.Table` object.
Names which contain no upper case characters
will be treated as case insensitive names, and will not be quoted
@@ -186,26 +190,34 @@ class Table(DialectKWArgs, SchemaItem, TableClause):
``quote=True`` to the constructor, or use the :class:`.quoted_name`
construct to specify the name.
- :param metadata: a :class:`.MetaData` object which will contain this
+ :param metadata: a :class:`_schema.MetaData`
+ object which will contain this
table. The metadata is used as a point of association of this table
with other tables which are referenced via foreign key. It also
may be used to associate this table with a particular
:class:`.Connectable`.
:param \*args: Additional positional arguments are used primarily
- to add the list of :class:`.Column` objects contained within this
+ to add the list of :class:`_schema.Column`
+ objects contained within this
table. Similar to the style of a CREATE TABLE statement, other
:class:`.SchemaItem` constructs may be added here, including
- :class:`.PrimaryKeyConstraint`, and :class:`.ForeignKeyConstraint`.
+ :class:`.PrimaryKeyConstraint`, and
+ :class:`_schema.ForeignKeyConstraint`.
- :param autoload: Defaults to False, unless :paramref:`.Table.autoload_with`
- is set in which case it defaults to True; :class:`.Column` objects
+ :param autoload: Defaults to False, unless
+ :paramref:`_schema.Table.autoload_with`
+ is set in which case it defaults to True; :class:`_schema.Column`
+ objects
for this table should be reflected from the database, possibly
- augmenting or replacing existing :class:`.Column` objects that were
+ augmenting or replacing existing :class:`_schema.Column`
+ objects that were
explicitly specified.
- .. versionchanged:: 1.0.0 setting the :paramref:`.Table.autoload_with`
- parameter implies that :paramref:`.Table.autoload` will default
+ .. versionchanged:: 1.0.0 setting the
+ :paramref:`_schema.Table.autoload_with`
+ parameter implies that :paramref:`_schema.Table.autoload`
+ will default
to True.
.. seealso::
@@ -213,69 +225,90 @@ class Table(DialectKWArgs, SchemaItem, TableClause):
:ref:`metadata_reflection_toplevel`
:param autoload_replace: Defaults to ``True``; when using
- :paramref:`.Table.autoload`
- in conjunction with :paramref:`.Table.extend_existing`, indicates
- that :class:`.Column` objects present in the already-existing
- :class:`.Table` object should be replaced with columns of the same
+ :paramref:`_schema.Table.autoload`
+ in conjunction with :paramref:`_schema.Table.extend_existing`,
+ indicates
+ that :class:`_schema.Column` objects present in the already-existing
+ :class:`_schema.Table`
+ object should be replaced with columns of the same
name retrieved from the autoload process. When ``False``, columns
already present under existing names will be omitted from the
reflection process.
- Note that this setting does not impact :class:`.Column` objects
- specified programmatically within the call to :class:`.Table` that
- also is autoloading; those :class:`.Column` objects will always
+ Note that this setting does not impact :class:`_schema.Column` objects
+ specified programmatically within the call to :class:`_schema.Table`
+ that
+ also is autoloading; those :class:`_schema.Column` objects will always
replace existing columns of the same name when
- :paramref:`.Table.extend_existing` is ``True``.
+ :paramref:`_schema.Table.extend_existing` is ``True``.
.. seealso::
- :paramref:`.Table.autoload`
+ :paramref:`_schema.Table.autoload`
- :paramref:`.Table.extend_existing`
+ :paramref:`_schema.Table.extend_existing`
- :param autoload_with: An :class:`.Engine` or :class:`.Connection` object,
- or a :class:`.Inspector` object as returned by :func:`.inspect`
- against one, with which this :class:`.Table` object will be reflected.
+ :param autoload_with: An :class:`_engine.Engine` or
+ :class:`_engine.Connection` object,
+ or a :class:`_reflection.Inspector` object as returned by
+ :func:`_sa.inspect`
+ against one, with which this :class:`_schema.Table`
+ object will be reflected.
When set to a non-None value, it implies that
- :paramref:`.Table.autoload` is ``True``. If left unset, but
- :paramref:`.Table.autoload` is explicitly set to ``True``, an autoload
- operation will attempt to proceed by locating an :class:`.Engine` or
- :class:`.Connection` bound to the underlying :class:`.MetaData` object.
+ :paramref:`_schema.Table.autoload` is ``True``. If left unset, but
+ :paramref:`_schema.Table.autoload` is explicitly set to ``True``,
+ an autoload
+ operation will attempt to proceed by locating an
+ :class:`_engine.Engine` or
+ :class:`_engine.Connection` bound to the underlying
+ :class:`_schema.MetaData` object.
.. seealso::
- :paramref:`.Table.autoload`
+ :paramref:`_schema.Table.autoload`
:param extend_existing: When ``True``, indicates that if this
- :class:`.Table` is already present in the given :class:`.MetaData`,
+ :class:`_schema.Table` is already present in the given
+ :class:`_schema.MetaData`,
apply further arguments within the constructor to the existing
- :class:`.Table`.
-
- If :paramref:`.Table.extend_existing` or
- :paramref:`.Table.keep_existing` are not set, and the given name
- of the new :class:`.Table` refers to a :class:`.Table` that is
- already present in the target :class:`.MetaData` collection, and
- this :class:`.Table` specifies additional columns or other constructs
+ :class:`_schema.Table`.
+
+ If :paramref:`_schema.Table.extend_existing` or
+ :paramref:`_schema.Table.keep_existing` are not set,
+ and the given name
+ of the new :class:`_schema.Table` refers to a :class:`_schema.Table`
+ that is
+ already present in the target :class:`_schema.MetaData` collection,
+ and
+ this :class:`_schema.Table`
+ specifies additional columns or other constructs
or flags that modify the table's state, an
error is raised. The purpose of these two mutually-exclusive flags
- is to specify what action should be taken when a :class:`.Table`
- is specified that matches an existing :class:`.Table`, yet specifies
+ is to specify what action should be taken when a
+ :class:`_schema.Table`
+ is specified that matches an existing :class:`_schema.Table`,
+ yet specifies
additional constructs.
- :paramref:`.Table.extend_existing` will also work in conjunction
- with :paramref:`.Table.autoload` to run a new reflection
- operation against the database, even if a :class:`.Table`
+ :paramref:`_schema.Table.extend_existing`
+ will also work in conjunction
+ with :paramref:`_schema.Table.autoload` to run a new reflection
+ operation against the database, even if a :class:`_schema.Table`
of the same name is already present in the target
- :class:`.MetaData`; newly reflected :class:`.Column` objects
+ :class:`_schema.MetaData`; newly reflected :class:`_schema.Column`
+ objects
and other options will be added into the state of the
- :class:`.Table`, potentially overwriting existing columns
+ :class:`_schema.Table`, potentially overwriting existing columns
and options of the same name.
- As is always the case with :paramref:`.Table.autoload`,
- :class:`.Column` objects can be specified in the same :class:`.Table`
+ As is always the case with :paramref:`_schema.Table.autoload`,
+ :class:`_schema.Column` objects can be specified in the same
+ :class:`_schema.Table`
constructor, which will take precedence. Below, the existing
- table ``mytable`` will be augmented with :class:`.Column` objects
- both reflected from the database, as well as the given :class:`.Column`
+ table ``mytable`` will be augmented with :class:`_schema.Column`
+ objects
+ both reflected from the database, as well as the given
+ :class:`_schema.Column`
named "y"::
Table("mytable", metadata,
@@ -287,11 +320,11 @@ class Table(DialectKWArgs, SchemaItem, TableClause):
.. seealso::
- :paramref:`.Table.autoload`
+ :paramref:`_schema.Table.autoload`
- :paramref:`.Table.autoload_replace`
+ :paramref:`_schema.Table.autoload_replace`
- :paramref:`.Table.keep_existing`
+ :paramref:`_schema.Table.keep_existing`
:param implicit_returning: True by default - indicates that
@@ -305,15 +338,20 @@ class Table(DialectKWArgs, SchemaItem, TableClause):
``Table`` object. Defaults to ``None`` which indicates all columns
should be reflected.
- :param resolve_fks: Whether or not to reflect :class:`.Table` objects
- related to this one via :class:`.ForeignKey` objects, when
- :paramref:`.Table.autoload` or :paramref:`.Table.autoload_with` is
+ :param resolve_fks: Whether or not to reflect :class:`_schema.Table`
+ objects
+ related to this one via :class:`_schema.ForeignKey` objects, when
+ :paramref:`_schema.Table.autoload` or
+ :paramref:`_schema.Table.autoload_with` is
specified. Defaults to True. Set to False to disable reflection of
- related tables as :class:`.ForeignKey` objects are encountered; may be
+ related tables as :class:`_schema.ForeignKey`
+ objects are encountered; may be
used either to save on SQL calls or to avoid issues with related tables
that can't be accessed. Note that if a related table is already present
- in the :class:`.MetaData` collection, or becomes present later, a
- :class:`.ForeignKey` object associated with this :class:`.Table` will
+ in the :class:`_schema.MetaData` collection, or becomes present later,
+ a
+ :class:`_schema.ForeignKey` object associated with this
+ :class:`_schema.Table` will
resolve to that table normally.
.. versionadded:: 1.3
@@ -327,34 +365,41 @@ class Table(DialectKWArgs, SchemaItem, TableClause):
:attr:`.SchemaItem.info` attribute of this object.
:param keep_existing: When ``True``, indicates that if this Table
- is already present in the given :class:`.MetaData`, ignore
+ is already present in the given :class:`_schema.MetaData`, ignore
further arguments within the constructor to the existing
- :class:`.Table`, and return the :class:`.Table` object as
+ :class:`_schema.Table`, and return the :class:`_schema.Table`
+ object as
originally created. This is to allow a function that wishes
- to define a new :class:`.Table` on first call, but on
- subsequent calls will return the same :class:`.Table`,
+ to define a new :class:`_schema.Table` on first call, but on
+ subsequent calls will return the same :class:`_schema.Table`,
without any of the declarations (particularly constraints)
being applied a second time.
- If :paramref:`.Table.extend_existing` or
- :paramref:`.Table.keep_existing` are not set, and the given name
- of the new :class:`.Table` refers to a :class:`.Table` that is
- already present in the target :class:`.MetaData` collection, and
- this :class:`.Table` specifies additional columns or other constructs
+ If :paramref:`_schema.Table.extend_existing` or
+ :paramref:`_schema.Table.keep_existing` are not set,
+ and the given name
+ of the new :class:`_schema.Table` refers to a :class:`_schema.Table`
+ that is
+ already present in the target :class:`_schema.MetaData` collection,
+ and
+ this :class:`_schema.Table`
+ specifies additional columns or other constructs
or flags that modify the table's state, an
error is raised. The purpose of these two mutually-exclusive flags
- is to specify what action should be taken when a :class:`.Table`
- is specified that matches an existing :class:`.Table`, yet specifies
+ is to specify what action should be taken when a
+ :class:`_schema.Table`
+ is specified that matches an existing :class:`_schema.Table`,
+ yet specifies
additional constructs.
.. seealso::
- :paramref:`.Table.extend_existing`
+ :paramref:`_schema.Table.extend_existing`
:param listeners: A list of tuples of the form ``(<eventname>, <fn>)``
which will be passed to :func:`.event.listen` upon construction.
This alternate hook to :func:`.event.listen` allows the establishment
- of a listener function specific to this :class:`.Table` before
+ of a listener function specific to this :class:`_schema.Table` before
the "autoload" process begins. Particularly useful for
the :meth:`.DDLEvents.column_reflect` event::
@@ -370,7 +415,7 @@ class Table(DialectKWArgs, SchemaItem, TableClause):
])
:param mustexist: When ``True``, indicates that this Table must already
- be present in the given :class:`.MetaData` collection, else
+ be present in the given :class:`_schema.MetaData` collection, else
an exception is raised.
:param prefixes:
@@ -391,16 +436,23 @@ class Table(DialectKWArgs, SchemaItem, TableClause):
the table resides in a schema other than the default selected schema
for the engine's database connection. Defaults to ``None``.
- If the owning :class:`.MetaData` of this :class:`.Table` specifies its
- own :paramref:`.MetaData.schema` parameter, then that schema name will
- be applied to this :class:`.Table` if the schema parameter here is set
- to ``None``. To set a blank schema name on a :class:`.Table` that
- would otherwise use the schema set on the owning :class:`.MetaData`,
+ If the owning :class:`_schema.MetaData` of this :class:`_schema.Table`
+ specifies its
+ own :paramref:`_schema.MetaData.schema` parameter,
+ then that schema name will
+ be applied to this :class:`_schema.Table`
+ if the schema parameter here is set
+ to ``None``. To set a blank schema name on a :class:`_schema.Table`
+ that
+ would otherwise use the schema set on the owning
+ :class:`_schema.MetaData`,
specify the special symbol :attr:`.BLANK_SCHEMA`.
.. versionadded:: 1.0.14 Added the :attr:`.BLANK_SCHEMA` symbol to
- allow a :class:`.Table` to have a blank schema name even when the
- parent :class:`.MetaData` specifies :paramref:`.MetaData.schema`.
+ allow a :class:`_schema.Table`
+ to have a blank schema name even when the
+ parent :class:`_schema.MetaData` specifies
+ :paramref:`_schema.MetaData.schema`.
The quoting rules for the schema name are the same as those for the
``name`` parameter, in that quoting is applied for reserved words or
@@ -411,8 +463,9 @@ class Table(DialectKWArgs, SchemaItem, TableClause):
:param comment: Optional string that will render an SQL comment on table
creation.
- .. versionadded:: 1.2 Added the :paramref:`.Table.comment` parameter
- to :class:`.Table`.
+ .. versionadded:: 1.2 Added the :paramref:`_schema.Table.comment`
+ parameter
+ to :class:`_schema.Table`.
:param \**kw: Additional keyword arguments not mentioned above are
dialect specific, and passed in the form ``<dialectname>_<argname>``.
@@ -482,10 +535,10 @@ class Table(DialectKWArgs, SchemaItem, TableClause):
metadata._remove_table(name, schema)
def __init__(self, *args, **kw):
- """Constructor for :class:`~.schema.Table`.
+ """Constructor for :class:`_schema.Table`.
This method is a no-op. See the top-level
- documentation for :class:`~.schema.Table`
+ documentation for :class:`_schema.Table`
for constructor arguments.
"""
@@ -596,10 +649,11 @@ class Table(DialectKWArgs, SchemaItem, TableClause):
@property
def foreign_key_constraints(self):
- """:class:`.ForeignKeyConstraint` objects referred to by this
- :class:`.Table`.
+ """:class:`_schema.ForeignKeyConstraint` objects referred to by this
+ :class:`_schema.Table`.
- This list is produced from the collection of :class:`.ForeignKey`
+ This list is produced from the collection of
+ :class:`_schema.ForeignKey`
objects currently associated.
.. versionadded:: 1.0.0
@@ -676,12 +730,13 @@ class Table(DialectKWArgs, SchemaItem, TableClause):
@property
def key(self):
- """Return the 'key' for this :class:`.Table`.
+ """Return the 'key' for this :class:`_schema.Table`.
This value is used as the dictionary key within the
- :attr:`.MetaData.tables` collection. It is typically the same
- as that of :attr:`.Table.name` for a table with no
- :attr:`.Table.schema` set; otherwise it is typically of the form
+ :attr:`_schema.MetaData.tables` collection. It is typically the same
+ as that of :attr:`_schema.Table.name` for a table with no
+ :attr:`_schema.Table.schema`
+ set; otherwise it is typically of the form
``schemaname.tablename``.
"""
@@ -719,13 +774,13 @@ class Table(DialectKWArgs, SchemaItem, TableClause):
self._extra_dependencies.add(table)
def append_column(self, column):
- """Append a :class:`~.schema.Column` to this :class:`~.schema.Table`.
+ """Append a :class:`_schema.Column` to this :class:`_schema.Table`.
- The "key" of the newly added :class:`~.schema.Column`, i.e. the
+ The "key" of the newly added :class:`_schema.Column`, i.e. the
value of its ``.key`` attribute, will then be available
- in the ``.c`` collection of this :class:`~.schema.Table`, and the
+ in the ``.c`` collection of this :class:`_schema.Table`, and the
column definition will be included in any CREATE TABLE, SELECT,
- UPDATE, etc. statements generated from this :class:`~.schema.Table`
+ UPDATE, etc. statements generated from this :class:`_schema.Table`
construct.
Note that this does **not** change the definition of the table
@@ -741,13 +796,13 @@ class Table(DialectKWArgs, SchemaItem, TableClause):
column._set_parent_with_dispatch(self)
def append_constraint(self, constraint):
- """Append a :class:`~.schema.Constraint` to this
- :class:`~.schema.Table`.
+ """Append a :class:`_schema.Constraint` to this
+ :class:`_schema.Table`.
This has the effect of the constraint being included in any
future CREATE TABLE statement, assuming specific DDL creation
events have not been associated with the given
- :class:`~.schema.Constraint` object.
+ :class:`_schema.Constraint` object.
Note that this does **not** produce the constraint within the
relational database automatically, for a table that already exists
@@ -782,9 +837,9 @@ class Table(DialectKWArgs, SchemaItem, TableClause):
@util.deprecated(
"1.4",
- "The :meth:`.Table.exists` method is deprecated and will be "
+ "The :meth:`_schema.Table.exists` method is deprecated and will be "
"removed in a future release. Please refer to "
- ":meth:`.Inspector.has_table`.",
+ ":meth:`_reflection.Inspector.has_table`.",
)
def exists(self, bind=None):
"""Return True if this table exists.
@@ -799,12 +854,12 @@ class Table(DialectKWArgs, SchemaItem, TableClause):
def create(self, bind=None, checkfirst=False):
"""Issue a ``CREATE`` statement for this
- :class:`.Table`, using the given :class:`.Connectable`
+ :class:`_schema.Table`, using the given :class:`.Connectable`
for connectivity.
.. seealso::
- :meth:`.MetaData.create_all`.
+ :meth:`_schema.MetaData.create_all`.
"""
@@ -814,12 +869,12 @@ class Table(DialectKWArgs, SchemaItem, TableClause):
def drop(self, bind=None, checkfirst=False):
"""Issue a ``DROP`` statement for this
- :class:`.Table`, using the given :class:`.Connectable`
+ :class:`_schema.Table`, using the given :class:`.Connectable`
for connectivity.
.. seealso::
- :meth:`.MetaData.drop_all`.
+ :meth:`_schema.MetaData.drop_all`.
"""
if bind is None:
@@ -833,8 +888,9 @@ class Table(DialectKWArgs, SchemaItem, TableClause):
referred_schema_fn=None,
name=None,
):
- """Return a copy of this :class:`.Table` associated with a different
- :class:`.MetaData`.
+ """Return a copy of this :class:`_schema.Table`
+ associated with a different
+ :class:`_schema.MetaData`.
E.g.::
@@ -845,16 +901,19 @@ class Table(DialectKWArgs, SchemaItem, TableClause):
m2 = MetaData()
user_copy = user.tometadata(m2)
- :param metadata: Target :class:`.MetaData` object, into which the
- new :class:`.Table` object will be created.
+ :param metadata: Target :class:`_schema.MetaData` object,
+ into which the
+ new :class:`_schema.Table` object will be created.
:param schema: optional string name indicating the target schema.
Defaults to the special symbol :attr:`.RETAIN_SCHEMA` which indicates
that no change to the schema name should be made in the new
- :class:`.Table`. If set to a string name, the new :class:`.Table`
+ :class:`_schema.Table`. If set to a string name, the new
+ :class:`_schema.Table`
will have this new name as the ``.schema``. If set to ``None``, the
schema will be set to that of the schema set on the target
- :class:`.MetaData`, which is typically ``None`` as well, unless
+ :class:`_schema.MetaData`, which is typically ``None`` as well,
+ unless
set explicitly::
m2 = MetaData(schema='newschema')
@@ -869,10 +928,10 @@ class Table(DialectKWArgs, SchemaItem, TableClause):
:param referred_schema_fn: optional callable which can be supplied
in order to provide for the schema name that should be assigned
- to the referenced table of a :class:`.ForeignKeyConstraint`.
- The callable accepts this parent :class:`.Table`, the
+ to the referenced table of a :class:`_schema.ForeignKeyConstraint`.
+ The callable accepts this parent :class:`_schema.Table`, the
target schema that we are changing to, the
- :class:`.ForeignKeyConstraint` object, and the existing
+ :class:`_schema.ForeignKeyConstraint` object, and the existing
"target schema" of that constraint. The function should return the
string schema name that should be applied.
E.g.::
@@ -891,7 +950,8 @@ class Table(DialectKWArgs, SchemaItem, TableClause):
:param name: optional string name indicating the target table name.
If not specified or None, the table name is retained. This allows
- a :class:`.Table` to be copied to the same :class:`.MetaData` target
+ a :class:`_schema.Table` to be copied to the same
+ :class:`_schema.MetaData` target
with a new name.
.. versionadded:: 1.0.0
@@ -985,7 +1045,7 @@ class Column(DialectKWArgs, SchemaItem, ColumnClause):
The name field may be omitted at construction time and applied
later, at any time before the Column is associated with a
- :class:`.Table`. This is to support convenient
+ :class:`_schema.Table`. This is to support convenient
usage within the :mod:`~sqlalchemy.ext.declarative` extension.
:param type\_: The column's type, indicated using an instance which
@@ -1004,21 +1064,24 @@ class Column(DialectKWArgs, SchemaItem, ColumnClause):
If the ``type`` is ``None`` or is omitted, it will first default to
the special type :class:`.NullType`. If and when this
- :class:`.Column` is made to refer to another column using
- :class:`.ForeignKey` and/or :class:`.ForeignKeyConstraint`, the type
+ :class:`_schema.Column` is made to refer to another column using
+ :class:`_schema.ForeignKey` and/or
+ :class:`_schema.ForeignKeyConstraint`, the type
of the remote-referenced column will be copied to this column as
well, at the moment that the foreign key is resolved against that
- remote :class:`.Column` object.
+ remote :class:`_schema.Column` object.
.. versionchanged:: 0.9.0
- Support for propagation of type to a :class:`.Column` from its
- :class:`.ForeignKey` object has been improved and should be
+ Support for propagation of type to a :class:`_schema.Column`
+ from its
+ :class:`_schema.ForeignKey` object has been improved and should be
more reliable and timely.
:param \*args: Additional positional arguments include various
:class:`.SchemaItem` derived constructs which will be applied
as options to the column. These include instances of
- :class:`.Constraint`, :class:`.ForeignKey`, :class:`.ColumnDefault`,
+ :class:`.Constraint`, :class:`_schema.ForeignKey`,
+ :class:`.ColumnDefault`,
:class:`.Sequence`, :class:`.Computed`. In some cases an
equivalent keyword argument is available such as ``server_default``,
``default`` and ``unique``.
@@ -1053,7 +1116,8 @@ class Column(DialectKWArgs, SchemaItem, ColumnClause):
(multi-column) primary keys, autoincrement is never implicitly
enabled; as always, ``autoincrement=True`` will allow for
at most one of those columns to be an "autoincrement" column.
- ``autoincrement=True`` may also be set on a :class:`.Column`
+ ``autoincrement=True`` may also be set on a
+ :class:`_schema.Column`
that has an explicit client-side or server-side default,
subject to limitations of the backend database and dialect.
@@ -1064,7 +1128,8 @@ class Column(DialectKWArgs, SchemaItem, ColumnClause):
* Part of the primary key
- * Not referring to another column via :class:`.ForeignKey`, unless
+ * Not referring to another column via :class:`_schema.ForeignKey`,
+ unless
the value is specified as ``'ignore_fk'``::
# turn on autoincrement for this column despite
@@ -1102,14 +1167,15 @@ class Column(DialectKWArgs, SchemaItem, ColumnClause):
:param default: A scalar, Python callable, or
- :class:`.ColumnElement` expression representing the
+ :class:`_expression.ColumnElement` expression representing the
*default value* for this column, which will be invoked upon insert
if this column is otherwise not specified in the VALUES clause of
the insert. This is a shortcut to using :class:`.ColumnDefault` as
a positional argument; see that class for full detail on the
structure of the argument.
- Contrast this argument to :paramref:`.Column.server_default`
+ Contrast this argument to
+ :paramref:`_schema.Column.server_default`
which creates a default generator on the database side.
.. seealso::
@@ -1118,11 +1184,13 @@ class Column(DialectKWArgs, SchemaItem, ColumnClause):
:param doc: optional String that can be used by the ORM or similar
to document attributes on the Python side. This attribute does
- **not** render SQL comments; use the :paramref:`.Column.comment`
+ **not** render SQL comments; use the
+ :paramref:`_schema.Column.comment`
parameter for this purpose.
:param key: An optional string identifier which will identify this
- ``Column`` object on the :class:`.Table`. When a key is provided,
+ ``Column`` object on the :class:`_schema.Table`.
+ When a key is provided,
this is the only identifier referencing the ``Column`` within the
application, including ORM attribute mapping; the ``name`` field
is used only when rendering SQL.
@@ -1141,7 +1209,8 @@ class Column(DialectKWArgs, SchemaItem, ColumnClause):
``True``, will normally generate nothing (in SQL this defaults to
"NULL"), except in some very specific backend-specific edge cases
where "NULL" may render explicitly. Defaults to ``True`` unless
- :paramref:`~.Column.primary_key` is also ``True``, in which case it
+ :paramref:`_schema.Column.primary_key` is also ``True``,
+ in which case it
defaults to ``False``. This parameter is only used when issuing
CREATE TABLE statements.
@@ -1160,7 +1229,7 @@ class Column(DialectKWArgs, SchemaItem, ColumnClause):
:param primary_key: If ``True``, marks this column as a primary key
column. Multiple columns can have this flag set to specify
composite primary keys. As an alternative, the primary key of a
- :class:`.Table` can be specified via an explicit
+ :class:`_schema.Table` can be specified via an explicit
:class:`.PrimaryKeyConstraint` object.
:param server_default: A :class:`.FetchedValue` instance, str, Unicode
@@ -1233,8 +1302,9 @@ class Column(DialectKWArgs, SchemaItem, ColumnClause):
:param comment: Optional string that will render an SQL comment on
table creation.
- .. versionadded:: 1.2 Added the :paramref:`.Column.comment`
- parameter to :class:`.Column`.
+ .. versionadded:: 1.2 Added the
+ :paramref:`_schema.Column.comment`
+ parameter to :class:`_schema.Column`.
"""
@@ -1600,7 +1670,8 @@ class Column(DialectKWArgs, SchemaItem, ColumnClause):
class ForeignKey(DialectKWArgs, SchemaItem):
"""Defines a dependency between two columns.
- ``ForeignKey`` is specified as an argument to a :class:`.Column` object,
+ ``ForeignKey`` is specified as an argument to a :class:`_schema.Column`
+ object,
e.g.::
t = Table("remote_table", metadata,
@@ -1609,24 +1680,26 @@ class ForeignKey(DialectKWArgs, SchemaItem):
Note that ``ForeignKey`` is only a marker object that defines
a dependency between two columns. The actual constraint
- is in all cases represented by the :class:`.ForeignKeyConstraint`
+ is in all cases represented by the :class:`_schema.ForeignKeyConstraint`
object. This object will be generated automatically when
- a ``ForeignKey`` is associated with a :class:`.Column` which
- in turn is associated with a :class:`.Table`. Conversely,
- when :class:`.ForeignKeyConstraint` is applied to a :class:`.Table`,
+ a ``ForeignKey`` is associated with a :class:`_schema.Column` which
+ in turn is associated with a :class:`_schema.Table`. Conversely,
+ when :class:`_schema.ForeignKeyConstraint` is applied to a
+ :class:`_schema.Table`,
``ForeignKey`` markers are automatically generated to be
- present on each associated :class:`.Column`, which are also
+ present on each associated :class:`_schema.Column`, which are also
associated with the constraint object.
Note that you cannot define a "composite" foreign key constraint,
that is a constraint between a grouping of multiple parent/child
columns, using ``ForeignKey`` objects. To define this grouping,
- the :class:`.ForeignKeyConstraint` object must be used, and applied
- to the :class:`.Table`. The associated ``ForeignKey`` objects
+ the :class:`_schema.ForeignKeyConstraint` object must be used, and applied
+ to the :class:`_schema.Table`. The associated ``ForeignKey`` objects
are created automatically.
The ``ForeignKey`` objects associated with an individual
- :class:`.Column` object are available in the `foreign_keys` collection
+ :class:`_schema.Column`
+ object are available in the `foreign_keys` collection
of that column.
Further examples of foreign key configuration are in
@@ -1654,12 +1727,13 @@ class ForeignKey(DialectKWArgs, SchemaItem):
r"""
Construct a column-level FOREIGN KEY.
- The :class:`.ForeignKey` object when constructed generates a
- :class:`.ForeignKeyConstraint` which is associated with the parent
- :class:`.Table` object's collection of constraints.
+ The :class:`_schema.ForeignKey` object when constructed generates a
+ :class:`_schema.ForeignKeyConstraint`
+ which is associated with the parent
+ :class:`_schema.Table` object's collection of constraints.
:param column: A single target column for the key relationship. A
- :class:`.Column` object or a column name as a string:
+ :class:`_schema.Column` object or a column name as a string:
``tablename.columnkey`` or ``schema.tablename.columnkey``.
``columnkey`` is the ``key`` which has been assigned to the column
(defaults to the column name itself), unless ``link_to_name`` is
@@ -1687,14 +1761,15 @@ class ForeignKey(DialectKWArgs, SchemaItem):
assigned ``key``.
:param use_alter: passed to the underlying
- :class:`.ForeignKeyConstraint` to indicate the constraint should
+ :class:`_schema.ForeignKeyConstraint`
+ to indicate the constraint should
be generated/dropped externally from the CREATE TABLE/ DROP TABLE
- statement. See :paramref:`.ForeignKeyConstraint.use_alter`
+ statement. See :paramref:`_schema.ForeignKeyConstraint.use_alter`
for further description.
.. seealso::
- :paramref:`.ForeignKeyConstraint.use_alter`
+ :paramref:`_schema.ForeignKeyConstraint.use_alter`
:ref:`use_alter`
@@ -1710,7 +1785,8 @@ class ForeignKey(DialectKWArgs, SchemaItem):
:param \**dialect_kw: Additional keyword arguments are dialect
specific, and passed in the form ``<dialectname>_<argname>``. The
arguments are ultimately handled by a corresponding
- :class:`.ForeignKeyConstraint`. See the documentation regarding
+ :class:`_schema.ForeignKeyConstraint`.
+ See the documentation regarding
an individual dialect at :ref:`dialect_toplevel` for detail on
documented arguments.
@@ -1756,16 +1832,16 @@ class ForeignKey(DialectKWArgs, SchemaItem):
return "ForeignKey(%r)" % self._get_colspec()
def copy(self, schema=None):
- """Produce a copy of this :class:`.ForeignKey` object.
+ """Produce a copy of this :class:`_schema.ForeignKey` object.
- The new :class:`.ForeignKey` will not be bound
- to any :class:`.Column`.
+ The new :class:`_schema.ForeignKey` will not be bound
+ to any :class:`_schema.Column`.
This method is usually used by the internal
- copy procedures of :class:`.Column`, :class:`.Table`,
- and :class:`.MetaData`.
+ copy procedures of :class:`_schema.Column`, :class:`_schema.Table`,
+ and :class:`_schema.MetaData`.
- :param schema: The returned :class:`.ForeignKey` will
+ :param schema: The returned :class:`_schema.ForeignKey` will
reference the original table and column name, qualified
by the given string schema name.
@@ -1787,7 +1863,7 @@ class ForeignKey(DialectKWArgs, SchemaItem):
def _get_colspec(self, schema=None, table_name=None):
"""Return a string based 'column specification' for this
- :class:`.ForeignKey`.
+ :class:`_schema.ForeignKey`.
This is usually the equivalent of the string-based "tablename.colname"
argument first passed to the object's constructor.
@@ -1829,17 +1905,20 @@ class ForeignKey(DialectKWArgs, SchemaItem):
target_fullname = property(_get_colspec)
def references(self, table):
- """Return True if the given :class:`.Table` is referenced by this
- :class:`.ForeignKey`."""
+ """Return True if the given :class:`_schema.Table`
+ is referenced by this
+ :class:`_schema.ForeignKey`."""
return table.corresponding_column(self.column) is not None
def get_referent(self, table):
- """Return the :class:`.Column` in the given :class:`.Table`
- referenced by this :class:`.ForeignKey`.
+ """Return the :class:`_schema.Column` in the given
+ :class:`_schema.Table`
+ referenced by this :class:`_schema.ForeignKey`.
- Returns None if this :class:`.ForeignKey` does not reference the given
- :class:`.Table`.
+ Returns None if this :class:`_schema.ForeignKey`
+ does not reference the given
+ :class:`_schema.Table`.
"""
@@ -1966,8 +2045,8 @@ class ForeignKey(DialectKWArgs, SchemaItem):
@util.memoized_property
def column(self):
- """Return the target :class:`.Column` referenced by this
- :class:`.ForeignKey`.
+ """Return the target :class:`_schema.Column` referenced by this
+ :class:`_schema.ForeignKey`.
If no target column has been established, an exception
is raised.
@@ -2097,7 +2176,8 @@ class DefaultGenerator(SchemaItem):
@util.deprecated_20(
":meth:`.DefaultGenerator.execute`",
alternative="All statement execution in SQLAlchemy 2.0 is performed "
- "by the :meth:`.Connection.execute` method of :class:`.Connection`, "
+ "by the :meth:`_engine.Connection.execute` method of "
+ ":class:`_engine.Connection`, "
"or in the ORM by the :meth:`.Session.execute` method of "
":class:`.Session`.",
)
@@ -2126,7 +2206,7 @@ class ColumnDefault(DefaultGenerator):
:class:`.ColumnDefault` is generated automatically
whenever the ``default``, ``onupdate`` arguments of
- :class:`.Column` are used. A :class:`.ColumnDefault`
+ :class:`_schema.Column` are used. A :class:`.ColumnDefault`
can be passed positionally as well.
For example, the following::
@@ -2151,7 +2231,7 @@ class ColumnDefault(DefaultGenerator):
string, integer, boolean, or other simple type.
The default value will be used as is each time.
* a SQL expression, that is one which derives from
- :class:`.ColumnElement`. The SQL expression will
+ :class:`_expression.ColumnElement`. The SQL expression will
be rendered into the INSERT or UPDATE statement,
or in the case of a primary key column when
RETURNING is not used may be
@@ -2162,7 +2242,7 @@ class ColumnDefault(DefaultGenerator):
zero or one positional arguments. The one-argument form
will receive an instance of the :class:`.ExecutionContext`,
which provides contextual information as to the current
- :class:`.Connection` in use as well as the current
+ :class:`_engine.Connection` in use as well as the current
statement and parameters.
"""
@@ -2236,8 +2316,9 @@ class Sequence(roles.StatementRole, DefaultGenerator):
The :class:`.Sequence` object represents the name and configurational
parameters of a database sequence. It also represents
- a construct that can be "executed" by a SQLAlchemy :class:`.Engine`
- or :class:`.Connection`, rendering the appropriate "next value" function
+ a construct that can be "executed" by a SQLAlchemy :class:`_engine.Engine`
+ or :class:`_engine.Connection`,
+ rendering the appropriate "next value" function
for the target database and returning a result.
The :class:`.Sequence` is typically associated with a primary key column::
@@ -2248,7 +2329,7 @@ class Sequence(roles.StatementRole, DefaultGenerator):
primary_key=True)
)
- When CREATE TABLE is emitted for the above :class:`.Table`, if the
+ When CREATE TABLE is emitted for the above :class:`_schema.Table`, if the
target platform supports sequences, a CREATE SEQUENCE statement will
be emitted as well. For platforms that don't support sequences,
the :class:`.Sequence` construct is ignored.
@@ -2348,8 +2429,9 @@ class Sequence(roles.StatementRole, DefaultGenerator):
:param schema: Optional schema name for the sequence, if located
in a schema other than the default. The rules for selecting the
- schema name when a :class:`.MetaData` is also present are the same
- as that of :paramref:`.Table.schema`.
+ schema name when a :class:`_schema.MetaData`
+ is also present are the same
+ as that of :paramref:`_schema.Table.schema`.
:param cache: optional integer value; number of future values in the
sequence which are calculated in advance. Renders the CACHE keyword
@@ -2377,27 +2459,32 @@ class Sequence(roles.StatementRole, DefaultGenerator):
:param quote_schema: set the quoting preferences for the ``schema``
name.
- :param metadata: optional :class:`.MetaData` object which this
+ :param metadata: optional :class:`_schema.MetaData` object which this
:class:`.Sequence` will be associated with. A :class:`.Sequence`
- that is associated with a :class:`.MetaData` gains the following
+ that is associated with a :class:`_schema.MetaData`
+ gains the following
capabilities:
- * The :class:`.Sequence` will inherit the :paramref:`.MetaData.schema`
- parameter specified to the target :class:`.MetaData`, which
+ * The :class:`.Sequence` will inherit the
+ :paramref:`_schema.MetaData.schema`
+ parameter specified to the target :class:`_schema.MetaData`, which
affects the production of CREATE / DROP DDL, if any.
* The :meth:`.Sequence.create` and :meth:`.Sequence.drop` methods
- automatically use the engine bound to the :class:`.MetaData`
+ automatically use the engine bound to the :class:`_schema.MetaData`
object, if any.
- * The :meth:`.MetaData.create_all` and :meth:`.MetaData.drop_all`
+ * The :meth:`_schema.MetaData.create_all` and
+ :meth:`_schema.MetaData.drop_all`
methods will emit CREATE / DROP for this :class:`.Sequence`,
even if the :class:`.Sequence` is not associated with any
- :class:`.Table` / :class:`.Column` that's a member of this
- :class:`.MetaData`.
+ :class:`_schema.Table` / :class:`_schema.Column`
+ that's a member of this
+ :class:`_schema.MetaData`.
The above behaviors can only occur if the :class:`.Sequence` is
- explicitly associated with the :class:`.MetaData` via this parameter.
+ explicitly associated with the :class:`_schema.MetaData`
+ via this parameter.
.. seealso::
@@ -2405,7 +2492,8 @@ class Sequence(roles.StatementRole, DefaultGenerator):
:paramref:`.Sequence.metadata` parameter.
:param for_update: Indicates this :class:`.Sequence`, when associated
- with a :class:`.Column`, should be invoked for UPDATE statements
+ with a :class:`_schema.Column`,
+ should be invoked for UPDATE statements
on that column's table, rather than for INSERT statements, when
no value is otherwise present for that column in the statement.
@@ -2555,7 +2643,7 @@ class DefaultClause(FetchedValue):
:class:`.DefaultClause` is generated automatically
whenever the ``server_default``, ``server_onupdate`` arguments of
- :class:`.Column` are used. A :class:`.DefaultClause`
+ :class:`_schema.Column` are used. A :class:`.DefaultClause`
can be passed positionally as well.
For example, the following::
@@ -2672,7 +2760,8 @@ class Constraint(DialectKWArgs, SchemaItem):
class ColumnCollectionMixin(object):
columns = None
- """A :class:`.ColumnCollection` of :class:`.Column` objects.
+ """A :class:`_expression.ColumnCollection` of :class:`_schema.Column`
+ objects.
This collection represents the columns which are referred to by
this object.
@@ -2799,7 +2888,7 @@ class ColumnCollectionConstraint(ColumnCollectionMixin, Constraint):
)
columns = None
- """A :class:`.ColumnCollection` representing the set of columns
+ """A :class:`_expression.ColumnCollection` representing the set of columns
for this constraint.
"""
@@ -2824,7 +2913,8 @@ class ColumnCollectionConstraint(ColumnCollectionMixin, Constraint):
"""Return True if this constraint contains the given column.
Note that this object also contains an attribute ``.columns``
- which is a :class:`.ColumnCollection` of :class:`.Column` objects.
+ which is a :class:`_expression.ColumnCollection` of
+ :class:`_schema.Column` objects.
"""
@@ -2870,7 +2960,8 @@ class CheckConstraint(ColumnCollectionConstraint):
:param sqltext:
A string containing the constraint definition, which will be used
verbatim, or a SQL expression construct. If given as a string,
- the object is converted to a :func:`.text` object. If the textual
+ the object is converted to a :func:`_expression.text` object.
+ If the textual
string includes a colon character, escape this using a backslash::
CheckConstraint(r"foo ~ E'a(?\:b|c)d")
@@ -2938,9 +3029,10 @@ class ForeignKeyConstraint(ColumnCollectionConstraint):
Defines a single column or composite FOREIGN KEY ... REFERENCES
constraint. For a no-frills, single column foreign key, adding a
- :class:`.ForeignKey` to the definition of a :class:`.Column` is a
+ :class:`_schema.ForeignKey` to the definition of a :class:`_schema.Column`
+ is a
shorthand equivalent for an unnamed, single column
- :class:`.ForeignKeyConstraint`.
+ :class:`_schema.ForeignKeyConstraint`.
Examples of foreign key configuration are in :ref:`metadata_foreignkeys`.
@@ -3000,16 +3092,17 @@ class ForeignKeyConstraint(ColumnCollectionConstraint):
have been created, and drop it via an ALTER TABLE statement before
the full collection of tables are dropped.
- The use of :paramref:`.ForeignKeyConstraint.use_alter` is
+ The use of :paramref:`_schema.ForeignKeyConstraint.use_alter` is
particularly geared towards the case where two or more tables
are established within a mutually-dependent foreign key constraint
- relationship; however, the :meth:`.MetaData.create_all` and
- :meth:`.MetaData.drop_all` methods will perform this resolution
+ relationship; however, the :meth:`_schema.MetaData.create_all` and
+ :meth:`_schema.MetaData.drop_all`
+ methods will perform this resolution
automatically, so the flag is normally not needed.
.. versionchanged:: 1.0.0 Automatic resolution of foreign key
cycles has been added, removing the need to use the
- :paramref:`.ForeignKeyConstraint.use_alter` in typical use
+ :paramref:`_schema.ForeignKeyConstraint.use_alter` in typical use
cases.
.. seealso::
@@ -3097,15 +3190,16 @@ class ForeignKeyConstraint(ColumnCollectionConstraint):
self.elements.append(fk)
columns = None
- """A :class:`.ColumnCollection` representing the set of columns
+ """A :class:`_expression.ColumnCollection` representing the set of columns
for this constraint.
"""
elements = None
- """A sequence of :class:`.ForeignKey` objects.
+ """A sequence of :class:`_schema.ForeignKey` objects.
- Each :class:`.ForeignKey` represents a single referring column/referred
+ Each :class:`_schema.ForeignKey`
+ represents a single referring column/referred
column pair.
This collection is intended to be read-only.
@@ -3126,8 +3220,8 @@ class ForeignKeyConstraint(ColumnCollectionConstraint):
@property
def referred_table(self):
- """The :class:`.Table` object to which this
- :class:`.ForeignKeyConstraint` references.
+ """The :class:`_schema.Table` object to which this
+ :class:`_schema.ForeignKeyConstraint` references.
This is a dynamically calculated attribute which may not be available
if the constraint and/or parent table is not yet associated with
@@ -3151,11 +3245,11 @@ class ForeignKeyConstraint(ColumnCollectionConstraint):
@property
def column_keys(self):
"""Return a list of string keys representing the local
- columns in this :class:`.ForeignKeyConstraint`.
+ columns in this :class:`_schema.ForeignKeyConstraint`.
This list is either the original string arguments sent
- to the constructor of the :class:`.ForeignKeyConstraint`,
- or if the constraint has been initialized with :class:`.Column`
+ to the constructor of the :class:`_schema.ForeignKeyConstraint`,
+ or if the constraint has been initialized with :class:`_schema.Column`
objects, is the string .key of each element.
.. versionadded:: 1.0.0
@@ -3225,9 +3319,9 @@ class PrimaryKeyConstraint(ColumnCollectionConstraint):
"""A table-level PRIMARY KEY constraint.
The :class:`.PrimaryKeyConstraint` object is present automatically
- on any :class:`.Table` object; it is assigned a set of
- :class:`.Column` objects corresponding to those marked with
- the :paramref:`.Column.primary_key` flag::
+ on any :class:`_schema.Table` object; it is assigned a set of
+ :class:`_schema.Column` objects corresponding to those marked with
+ the :paramref:`_schema.Column.primary_key` flag::
>>> my_table = Table('mytable', metadata,
... Column('id', Integer, primary_key=True),
@@ -3242,7 +3336,7 @@ class PrimaryKeyConstraint(ColumnCollectionConstraint):
primary_key=True, nullable=False)
)
- The primary key of a :class:`.Table` can also be specified by using
+ The primary key of a :class:`_schema.Table` can also be specified by using
a :class:`.PrimaryKeyConstraint` object explicitly; in this mode of usage,
the "name" of the constraint can also be specified, as well as other
options which may be recognized by dialects::
@@ -3275,7 +3369,7 @@ class PrimaryKeyConstraint(ColumnCollectionConstraint):
:class:`.PrimaryKeyConstraint`, but the usual style of using
``primary_key=True`` flags is still desirable, an empty
:class:`.PrimaryKeyConstraint` may be specified, which will take on the
- primary key column collection from the :class:`.Table` based on the
+ primary key column collection from the :class:`_schema.Table` based on the
flags::
my_table = Table('mytable', metadata,
@@ -3289,7 +3383,7 @@ class PrimaryKeyConstraint(ColumnCollectionConstraint):
.. versionadded:: 0.9.2 an empty :class:`.PrimaryKeyConstraint` may now
be specified for the purposes of establishing keyword arguments with
the constraint, independently of the specification of "primary key"
- columns within the :class:`.Table` itself; columns marked as
+ columns within the :class:`_schema.Table` itself; columns marked as
``primary_key=True`` will be gathered into the empty constraint's
column collection.
@@ -3342,7 +3436,7 @@ class PrimaryKeyConstraint(ColumnCollectionConstraint):
This is basically like putting a whole new
:class:`.PrimaryKeyConstraint` object on the parent
- :class:`.Table` object without actually replacing the object.
+ :class:`_schema.Table` object without actually replacing the object.
The ordering of the given list of columns is also maintained; these
columns will be appended to the list of columns after any which
@@ -3457,7 +3551,7 @@ class Index(DialectKWArgs, ColumnCollectionMixin, SchemaItem):
Index("some_index", sometable.c.name)
For a no-frills, single column index, adding
- :class:`.Column` also supports ``index=True``::
+ :class:`_schema.Column` also supports ``index=True``::
sometable = Table("sometable", metadata,
Column("name", String(50), index=True)
@@ -3469,13 +3563,15 @@ class Index(DialectKWArgs, ColumnCollectionMixin, SchemaItem):
Functional indexes are supported as well, typically by using the
:data:`.func` construct in conjunction with table-bound
- :class:`.Column` objects::
+ :class:`_schema.Column` objects::
Index("some_index", func.lower(sometable.c.name))
- An :class:`.Index` can also be manually associated with a :class:`.Table`,
+ An :class:`.Index` can also be manually associated with a
+ :class:`_schema.Table`,
either through inline declaration or using
- :meth:`.Table.append_constraint`. When this approach is used, the names
+ :meth:`_schema.Table.append_constraint`. When this approach is used,
+ the names
of the indexed columns can be specified as strings::
Table("sometable", metadata,
@@ -3485,7 +3581,7 @@ class Index(DialectKWArgs, ColumnCollectionMixin, SchemaItem):
)
To support functional or expression-based indexes in this form, the
- :func:`.text` construct may be used::
+ :func:`_expression.text` construct may be used::
from sqlalchemy import text
@@ -3495,9 +3591,10 @@ class Index(DialectKWArgs, ColumnCollectionMixin, SchemaItem):
Index("some_index", text("lower(name)"))
)
- .. versionadded:: 0.9.5 the :func:`.text` construct may be used to
+ .. versionadded:: 0.9.5 the :func:`_expression.text`
+ construct may be used to
specify :class:`.Index` expressions, provided the :class:`.Index`
- is explicitly associated with the :class:`.Table`.
+ is explicitly associated with the :class:`_schema.Table`.
.. seealso::
@@ -3525,9 +3622,9 @@ class Index(DialectKWArgs, ColumnCollectionMixin, SchemaItem):
:param \*expressions:
Column expressions to include in the index. The expressions
- are normally instances of :class:`.Column`, but may also
+ are normally instances of :class:`_schema.Column`, but may also
be arbitrary SQL expressions which ultimately refer to a
- :class:`.Column`.
+ :class:`_schema.Column`.
:param unique=False:
Keyword only argument; if True, create a unique index.
@@ -3535,7 +3632,7 @@ class Index(DialectKWArgs, ColumnCollectionMixin, SchemaItem):
:param quote=None:
Keyword only argument; whether to apply quoting to the name of
the index. Works in the same manner as that of
- :paramref:`.Column.quote`.
+ :paramref:`_schema.Column.quote`.
:param info=None: Optional data dictionary which will be populated
into the :attr:`.SchemaItem.info` attribute of this object.
@@ -3610,7 +3707,7 @@ class Index(DialectKWArgs, ColumnCollectionMixin, SchemaItem):
.. seealso::
- :meth:`.MetaData.create_all`.
+ :meth:`_schema.MetaData.create_all`.
"""
if bind is None:
@@ -3625,7 +3722,7 @@ class Index(DialectKWArgs, ColumnCollectionMixin, SchemaItem):
.. seealso::
- :meth:`.MetaData.drop_all`.
+ :meth:`_schema.MetaData.drop_all`.
"""
if bind is None:
@@ -3646,20 +3743,22 @@ DEFAULT_NAMING_CONVENTION = util.immutabledict({"ix": "ix_%(column_0_label)s"})
class MetaData(SchemaItem):
- """A collection of :class:`.Table` objects and their associated schema
+ """A collection of :class:`_schema.Table`
+ objects and their associated schema
constructs.
- Holds a collection of :class:`.Table` objects as well as
- an optional binding to an :class:`.Engine` or
- :class:`.Connection`. If bound, the :class:`.Table` objects
+ Holds a collection of :class:`_schema.Table` objects as well as
+ an optional binding to an :class:`_engine.Engine` or
+ :class:`_engine.Connection`. If bound, the :class:`_schema.Table` objects
in the collection and their columns may participate in implicit SQL
execution.
- The :class:`.Table` objects themselves are stored in the
- :attr:`.MetaData.tables` dictionary.
+ The :class:`_schema.Table` objects themselves are stored in the
+ :attr:`_schema.MetaData.tables` dictionary.
- :class:`.MetaData` is a thread-safe object for read operations.
- Construction of new tables within a single :class:`.MetaData` object,
+ :class:`_schema.MetaData` is a thread-safe object for read operations.
+ Construction of new tables within a single :class:`_schema.MetaData`
+ object,
either explicitly or via reflection, may not be completely thread-safe.
.. seealso::
@@ -3690,37 +3789,46 @@ class MetaData(SchemaItem):
Defaults to False. ``bind`` is required when this option is set.
:param schema:
- The default schema to use for the :class:`.Table`,
+ The default schema to use for the :class:`_schema.Table`,
:class:`.Sequence`, and potentially other objects associated with
- this :class:`.MetaData`. Defaults to ``None``.
+ this :class:`_schema.MetaData`. Defaults to ``None``.
- When this value is set, any :class:`.Table` or :class:`.Sequence`
+ When this value is set, any :class:`_schema.Table` or
+ :class:`.Sequence`
which specifies ``None`` for the schema parameter will instead
- have this schema name defined. To build a :class:`.Table`
+ have this schema name defined. To build a :class:`_schema.Table`
or :class:`.Sequence` that still has ``None`` for the schema
even when this parameter is present, use the :attr:`.BLANK_SCHEMA`
symbol.
.. note::
- As referred above, the :paramref:`.MetaData.schema` parameter
+ As referred above, the :paramref:`_schema.MetaData.schema`
+ parameter
only refers to the **default value** that will be applied to
- the :paramref:`.Table.schema` parameter of an incoming
- :class:`.Table` object. It does not refer to how the
- :class:`.Table` is catalogued within the :class:`.MetaData`,
- which remains consistent vs. a :class:`.MetaData` collection
- that does not define this parameter. The :class:`.Table`
- within the :class:`.MetaData` will still be keyed based on its
+ the :paramref:`_schema.Table.schema` parameter of an incoming
+ :class:`_schema.Table` object. It does not refer to how the
+ :class:`_schema.Table` is catalogued within the
+ :class:`_schema.MetaData`,
+ which remains consistent vs. a :class:`_schema.MetaData`
+ collection
+ that does not define this parameter. The
+ :class:`_schema.Table`
+ within the :class:`_schema.MetaData`
+ will still be keyed based on its
schema-qualified name, e.g.
``my_metadata.tables["some_schema.my_table"]``.
- The current behavior of the :class:`.ForeignKey` object is to
+ The current behavior of the :class:`_schema.ForeignKey`
+ object is to
circumvent this restriction, where it can locate a table given
the table name alone, where the schema will be assumed to be
present from this value as specified on the owning
- :class:`.MetaData` collection. However, this implies that a
+ :class:`_schema.MetaData` collection. However,
+ this implies that a
table qualified with BLANK_SCHEMA cannot currently be referred
- to by string name from :class:`.ForeignKey`. Other parts of
+ to by string name from :class:`_schema.ForeignKey`.
+ Other parts of
SQLAlchemy such as Declarative may not have similar behaviors
built in, however may do so in a future release, along with a
consistent method of referring to a table in BLANK_SCHEMA.
@@ -3728,12 +3836,12 @@ class MetaData(SchemaItem):
.. seealso::
- :paramref:`.Table.schema`
+ :paramref:`_schema.Table.schema`
:paramref:`.Sequence.schema`
:param quote_schema:
- Sets the ``quote_schema`` flag for those :class:`.Table`,
+ Sets the ``quote_schema`` flag for those :class:`_schema.Table`,
:class:`.Sequence`, and other objects which make usage of the
local ``schema`` name.
@@ -3750,7 +3858,8 @@ class MetaData(SchemaItem):
The keys of this dictionary may be:
* a constraint or Index class, e.g. the :class:`.UniqueConstraint`,
- :class:`.ForeignKeyConstraint` class, the :class:`.Index` class
+ :class:`_schema.ForeignKeyConstraint` class, the :class:`.Index`
+ class
* a string mnemonic for one of the known constraint classes;
``"fk"``, ``"pk"``, ``"ix"``, ``"ck"``, ``"uq"`` for foreign key,
@@ -3765,45 +3874,49 @@ class MetaData(SchemaItem):
which describe how the name should be composed. The values
associated with user-defined "token" keys should be callables of the
form ``fn(constraint, table)``, which accepts the constraint/index
- object and :class:`.Table` as arguments, returning a string
+ object and :class:`_schema.Table` as arguments, returning a string
result.
The built-in names are as follows, some of which may only be
available for certain types of constraint:
- * ``%(table_name)s`` - the name of the :class:`.Table` object
+ * ``%(table_name)s`` - the name of the :class:`_schema.Table`
+ object
associated with the constraint.
- * ``%(referred_table_name)s`` - the name of the :class:`.Table`
+ * ``%(referred_table_name)s`` - the name of the
+ :class:`_schema.Table`
object associated with the referencing target of a
- :class:`.ForeignKeyConstraint`.
+ :class:`_schema.ForeignKeyConstraint`.
- * ``%(column_0_name)s`` - the name of the :class:`.Column` at
+ * ``%(column_0_name)s`` - the name of the :class:`_schema.Column`
+ at
index position "0" within the constraint.
- * ``%(column_0N_name)s`` - the name of all :class:`.Column`
+ * ``%(column_0N_name)s`` - the name of all :class:`_schema.Column`
objects in order within the constraint, joined without a
separator.
- * ``%(column_0_N_name)s`` - the name of all :class:`.Column`
+ * ``%(column_0_N_name)s`` - the name of all
+ :class:`_schema.Column`
objects in order within the constraint, joined with an
underscore as a separator.
* ``%(column_0_label)s``, ``%(column_0N_label)s``,
``%(column_0_N_label)s`` - the label of either the zeroth
- :class:`.Column` or all :class:`.Columns`, separated with
+ :class:`_schema.Column` or all :class:`.Columns`, separated with
or without an underscore
* ``%(column_0_key)s``, ``%(column_0N_key)s``,
``%(column_0_N_key)s`` - the key of either the zeroth
- :class:`.Column` or all :class:`.Columns`, separated with
+ :class:`_schema.Column` or all :class:`.Columns`, separated with
or without an underscore
* ``%(referred_column_0_name)s``, ``%(referred_column_0N_name)s``
``%(referred_column_0_N_name)s``, ``%(referred_column_0_key)s``,
``%(referred_column_0N_key)s``, ... column tokens which
render the names/keys/labels of columns that are referenced
- by a :class:`.ForeignKeyConstraint`.
+ by a :class:`_schema.ForeignKeyConstraint`.
* ``%(constraint_name)s`` - a special key that refers to the
existing name given to the constraint. When this key is
@@ -3843,16 +3956,20 @@ class MetaData(SchemaItem):
self.bind = bind
tables = None
- """A dictionary of :class:`.Table` objects keyed to their name or "table key".
-
- The exact key is that determined by the :attr:`.Table.key` attribute;
- for a table with no :attr:`.Table.schema` attribute, this is the same
- as :attr:`.Table.name`. For a table with a schema, it is typically of the
+ """A dictionary of :class:`_schema.Table`
+ objects keyed to their name or "table key".
+
+ The exact key is that determined by the :attr:`_schema.Table.key`
+ attribute;
+ for a table with no :attr:`_schema.Table.schema` attribute,
+ this is the same
+ as :attr:`_schema.Table.name`. For a table with a schema,
+ it is typically of the
form ``schemaname.tablename``.
.. seealso::
- :attr:`.MetaData.sorted_tables`
+ :attr:`_schema.MetaData.sorted_tables`
"""
@@ -3910,10 +4027,11 @@ class MetaData(SchemaItem):
return self._bind is not None
def bind(self):
- """An :class:`.Engine` or :class:`.Connection` to which this
- :class:`.MetaData` is bound.
+ """An :class:`_engine.Engine` or :class:`_engine.Connection`
+ to which this
+ :class:`_schema.MetaData` is bound.
- Typically, a :class:`.Engine` is assigned to this attribute
+ Typically, a :class:`_engine.Engine` is assigned to this attribute
so that "implicit execution" may be used, or alternatively
as a means of providing engine binding information to an
ORM :class:`.Session` object::
@@ -3953,10 +4071,11 @@ class MetaData(SchemaItem):
@property
def sorted_tables(self):
- """Returns a list of :class:`.Table` objects sorted in order of
+ """Returns a list of :class:`_schema.Table` objects sorted in order of
foreign key dependency.
- The sorting will place :class:`.Table` objects that have dependencies
+ The sorting will place :class:`_schema.Table`
+ objects that have dependencies
first, before the dependencies themselves, representing the
order in which they can be created. To get the order in which
the tables would be dropped, use the ``reversed()`` Python built-in.
@@ -3967,22 +4086,23 @@ class MetaData(SchemaItem):
automatic resolution of dependency cycles between tables, which
are usually caused by mutually dependent foreign key constraints.
To resolve these cycles, either the
- :paramref:`.ForeignKeyConstraint.use_alter` parameter may be
+ :paramref:`_schema.ForeignKeyConstraint.use_alter`
+ parameter may be
applied to those constraints, or use the
- :func:`.schema.sort_tables_and_constraints` function which will
+ :func:`_schema.sort_tables_and_constraints` function which will
break out foreign key constraints involved in cycles separately.
.. seealso::
- :func:`.schema.sort_tables`
+ :func:`_schema.sort_tables`
- :func:`.schema.sort_tables_and_constraints`
+ :func:`_schema.sort_tables_and_constraints`
- :attr:`.MetaData.tables`
+ :attr:`_schema.MetaData.tables`
- :meth:`.Inspector.get_table_names`
+ :meth:`_reflection.Inspector.get_table_names`
- :meth:`.Inspector.get_sorted_table_and_fkc_names`
+ :meth:`_reflection.Inspector.get_sorted_table_and_fkc_names`
"""
@@ -4015,7 +4135,7 @@ class MetaData(SchemaItem):
:param schema:
Optional, query and reflect tables from an alternate schema.
- If None, the schema associated with this :class:`.MetaData`
+ If None, the schema associated with this :class:`_schema.MetaData`
is used, if any.
:param views:
@@ -4035,35 +4155,41 @@ class MetaData(SchemaItem):
with a table name and this ``MetaData`` instance as positional
arguments and should return a true value for any table to reflect.
- :param extend_existing: Passed along to each :class:`.Table` as
- :paramref:`.Table.extend_existing`.
+ :param extend_existing: Passed along to each :class:`_schema.Table` as
+ :paramref:`_schema.Table.extend_existing`.
.. versionadded:: 0.9.1
- :param autoload_replace: Passed along to each :class:`.Table` as
- :paramref:`.Table.autoload_replace`.
+ :param autoload_replace: Passed along to each :class:`_schema.Table`
+ as
+ :paramref:`_schema.Table.autoload_replace`.
.. versionadded:: 0.9.1
- :param resolve_fks: if True, reflect :class:`.Table` objects linked
- to :class:`.ForeignKey` objects located in each :class:`.Table`.
- For :meth:`.MetaData.reflect`, this has the effect of reflecting
+ :param resolve_fks: if True, reflect :class:`_schema.Table`
+ objects linked
+ to :class:`_schema.ForeignKey` objects located in each
+ :class:`_schema.Table`.
+ For :meth:`_schema.MetaData.reflect`,
+ this has the effect of reflecting
related tables that might otherwise not be in the list of tables
being reflected, for example if the referenced table is in a
different schema or is omitted via the
:paramref:`.MetaData.reflect.only` parameter. When False,
- :class:`.ForeignKey` objects are not followed to the :class:`.Table`
+ :class:`_schema.ForeignKey` objects are not followed to the
+ :class:`_schema.Table`
in which they link, however if the related table is also part of the
list of tables that would be reflected in any case, the
- :class:`.ForeignKey` object will still resolve to its related
- :class:`.Table` after the :meth:`.MetaData.reflect` operation is
+ :class:`_schema.ForeignKey` object will still resolve to its related
+ :class:`_schema.Table` after the :meth:`_schema.MetaData.reflect`
+ operation is
complete. Defaults to True.
.. versionadded:: 1.3.0
.. seealso::
- :paramref:`.Table.resolve_fks`
+ :paramref:`_schema.Table.resolve_fks`
:param \**dialect_kwargs: Additional keyword arguments not mentioned
above are dialect specific, and passed in the form
@@ -4073,7 +4199,7 @@ class MetaData(SchemaItem):
.. versionadded:: 0.9.2 - Added
:paramref:`.MetaData.reflect.**dialect_kwargs` to support
- dialect-level reflection options for all :class:`.Table`
+ dialect-level reflection options for all :class:`_schema.Table`
objects reflected.
"""
@@ -4273,7 +4399,7 @@ class Computed(FetchedValue, SchemaItem):
"""Defines a generated column, i.e. "GENERATED ALWAYS AS" syntax.
The :class:`.Computed` construct is an inline construct added to the
- argument list of a :class:`.Column` object::
+ argument list of a :class:`_schema.Column` object::
from sqlalchemy import Computed
@@ -4299,13 +4425,14 @@ class Computed(FetchedValue, SchemaItem):
)
def __init__(self, sqltext, persisted=None):
"""Construct a GENERATED ALWAYS AS DDL construct to accompany a
- :class:`.Column`.
+ :class:`_schema.Column`.
:param sqltext:
A string containing the column generation expression, which will be
- used verbatim, or a SQL expression construct, such as a :func:`.text`
+ used verbatim, or a SQL expression construct, such as a
+ :func:`_expression.text`
object. If given as a string, the object is converted to a
- :func:`.text` object.
+ :func:`_expression.text` object.
:param persisted:
Optional, controls how this column should be persisted by the