class Table(DialectKWArgs, HasSchemaAttr, TableClause, inspection.Inspectable[
Represent a table in a database. e.g.:: mytable = Table( "mytable", metadata, Column('mytable_id', Integer, primary_key=True), Column('value', String(50)) ) The :class:`_schema.Table` object constructs a unique instance of itself based on its name and optional schema name within the given :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:: :ref:`metadata_describing` - Introduction to database metadata
Method | __init__ |
Constructor for :class:`_schema.Table`. |
Method | __new__ |
Undocumented |
Method | __repr__ |
Undocumented |
Method | __str__ |
Undocumented |
Method | add |
Add a 'dependency' for this Table. |
Method | append |
Append a :class:`_schema.Column` to this :class:`_schema.Table`. |
Method | append |
Append a :class:`_schema.Constraint` to this :class:`_schema.Table`. |
Method | create |
Issue a ``CREATE`` statement for this :class:`_schema.Table`, using the given :class:`.Connection` or :class:`.Engine` for connectivity. |
Method | drop |
Issue a ``DROP`` statement for this :class:`_schema.Table`, using the given :class:`.Connection` or :class:`.Engine` for connectivity. |
Method | to |
Return a copy of this :class:`_schema.Table` associated with a different :class:`_schema.MetaData`. |
Method | tometadata |
Return a copy of this :class:`_schema.Table` associated with a different :class:`_schema.MetaData`. |
Class Variable | __visit |
Undocumented |
Instance Variable | comment |
Undocumented |
Instance Variable | constraints |
A collection of all :class:`_schema.Constraint` objects associated with this :class:`_schema.Table`. |
Instance Variable | foreign |
Return the collection of :class:`_schema.ForeignKey` marker objects which this FromClause references. |
Instance Variable | fullname |
Undocumented |
Instance Variable | implicit |
:class:`_expression.TableClause` doesn't support having a primary key or column -level defaults, so implicit returning doesn't apply. |
Instance Variable | indexes |
A collection of all :class:`_schema.Index` objects associated with this :class:`_schema.Table`. |
Instance Variable | info |
Info dictionary associated with the object, allowing user-defined data to be associated with this :class:`.SchemaItem`. |
Instance Variable | metadata |
Undocumented |
Instance Variable | schema |
Define the 'schema' attribute for this :class:`_expression.FromClause`. |
Property | autoincrement |
Returns the :class:`.Column` object which currently represents the "auto increment" column, if any, else returns None. |
Property | c |
A synonym for :attr:`.FromClause.columns` |
Property | columns |
A named-based collection of :class:`_expression.ColumnElement` objects maintained by this :class:`_expression.FromClause`. |
Property | exported |
A :class:`_expression.ColumnCollection` that represents the "exported" columns of this :class:`_expression.Selectable`. |
Property | foreign |
:class:`_schema.ForeignKeyConstraint` objects referred to by this :class:`_schema.Table`. |
Property | key |
Return the 'key' for this :class:`_schema.Table`. |
Property | primary |
Return the iterable collection of :class:`_schema.Column` objects which comprise the primary key of this :class:`_selectable.FromClause`. |
Class Method | _new |
Undocumented |
Method | _autoload |
Undocumented |
Method | _extra |
Undocumented |
Method | _gen |
return an optional cache key. |
Method | _init |
Undocumented |
Method | _init |
Undocumented |
Method | _reset |
Undocumented |
Method | _set |
Associate with this SchemaEvent's parent object. |
Class Variable | _columns |
Undocumented |
Class Variable | _traverse |
Undocumented |
Instance Variable | _extra |
Undocumented |
Instance Variable | _prefixes |
Undocumented |
Property | _autoincrement |
No PK or default support so no autoincrement column. |
Property | _sorted |
Return the set of constraints as a list, sorted by creation order. |
Inherited from DialectKWArgs
:
Class Method | argument |
Add a new kind of dialect-specific keyword argument for this class. |
Class Variable | __slots__ |
Undocumented |
Property | dialect |
A collection of keyword arguments specified as dialect-specific options to this construct. |
Property | dialect |
A collection of keyword arguments specified as dialect-specific options to this construct. |
Property | kwargs |
A synonym for :attr:`.DialectKWArgs.dialect_kwargs`. |
Method | _kw |
Undocumented |
Method | _validate |
Undocumented |
Class Variable | _dialect |
Undocumented |
Class Variable | _kw |
Undocumented |
Inherited from SchemaItem
(via DialectKWArgs
, HasSchemaAttr
):
Class Variable | create |
Undocumented |
Method | _init |
Initialize the list of child items for this SchemaItem. |
Method | _schema |
Undocumented |
Class Variable | _use |
Undocumented |
Inherited from SchemaEventTarget
(via DialectKWArgs
, HasSchemaAttr
, SchemaItem
):
Class Variable | dispatch |
Undocumented |
Method | _set |
Undocumented |
Inherited from TableClause
(via DialectKWArgs
, HasSchemaAttr
, SchemaItem
, SchemaEventTarget
, EventTarget
):
Method | delete |
Generate a :func:`_expression.delete` construct against this :class:`_expression.TableClause`. |
Method | insert |
Generate an :class:`_sql.Insert` construct against this :class:`_expression.TableClause`. |
Method | update |
Generate an :func:`_expression.update` construct against this :class:`_expression.TableClause`. |
Instance Variable | name |
Undocumented |
Property | description |
A brief description of this :class:`_expression.FromClause`. |
Method | _refresh |
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. |
Class Variable | _is |
Undocumented |
Property | _from |
Undocumented |
Inherited from DMLTableRole
(via DialectKWArgs
, HasSchemaAttr
, SchemaItem
, SchemaEventTarget
, EventTarget
, TableClause
):
Class Variable | _role |
Undocumented |
Inherited from Immutable
(via DialectKWArgs
, HasSchemaAttr
, SchemaItem
, SchemaEventTarget
, EventTarget
, TableClause
, DMLTableRole
):
Method | params |
Undocumented |
Method | unique |
Undocumented |
Method | _clone |
Undocumented |
Method | _copy |
Undocumented |
Class Variable | _is |
Undocumented |
Inherited from NamedFromClause
(via DialectKWArgs
, HasSchemaAttr
, SchemaItem
, SchemaEventTarget
, EventTarget
, TableClause
, DMLTableRole
, Immutable
):
Method | table |
Return a :class:`_sql.TableValuedColumn` object for this :class:`_expression.FromClause`. |
Class Variable | named |
Undocumented |
Inherited from FromClause
(via DialectKWArgs
, HasSchemaAttr
, SchemaItem
, SchemaEventTarget
, EventTarget
, TableClause
, DMLTableRole
, Immutable
, NamedFromClause
):
Method | alias |
Return an alias of this :class:`_expression.FromClause`. |
Method | is |
Return ``True`` if this :class:`_expression.FromClause` is 'derived' from the given ``FromClause``. |
Method | join |
Return a :class:`_expression.Join` from this :class:`_expression.FromClause` to another :class:`FromClause`. |
Method | outerjoin |
Return a :class:`_expression.Join` from this :class:`_expression.FromClause` to another :class:`FromClause`, with the "isouter" flag set to True. |
Method | select |
Return a SELECT of this :class:`_expression.FromClause`. |
Method | self |
Apply a 'grouping' to this :class:`_expression.ClauseElement`. |
Method | tablesample |
Return a TABLESAMPLE alias of this :class:`_expression.FromClause`. |
Class Variable | is |
Undocumented |
Property | entity |
Return a namespace used for name-based access in SQL expressions. |
Method | _anonymous |
Undocumented |
Method | _generate |
Populate columns into an :class:`.AliasedReturnsRows` object. |
Method | _is |
Return ``True`` if this :class:`_expression.FromClause` and the other represent the same lexical identity. |
Method | _populate |
Called on subclasses to establish the .c collection. |
Method | _reset |
Reset the attributes linked to the ``FromClause.c`` attribute. |
Class Variable | _is |
Undocumented |
Class Variable | _is |
Undocumented |
Class Variable | _is |
Undocumented |
Property | _cols |
Undocumented |
Property | _hide |
Undocumented |
Property | _select |
Undocumented |
Inherited from FromClauseRole
(via DialectKWArgs
, HasSchemaAttr
, SchemaItem
, SchemaEventTarget
, EventTarget
, TableClause
, DMLTableRole
, Immutable
, NamedFromClause
, FromClause
, AnonymizedFromClauseRole
, StrictFromClauseRole
):
Class Variable | _is |
Undocumented |
Inherited from AllowsLambdaRole
(via DialectKWArgs
, HasSchemaAttr
, SchemaItem
, SchemaEventTarget
, EventTarget
, TableClause
, DMLTableRole
, Immutable
, NamedFromClause
, FromClause
, AnonymizedFromClauseRole
, StrictFromClauseRole
, FromClauseRole
, ColumnsClauseRole
, JoinTargetRole
):
Class Variable | allows |
Undocumented |
Inherited from UsesInspection
(via DialectKWArgs
, HasSchemaAttr
, SchemaItem
, SchemaEventTarget
, EventTarget
, TableClause
, DMLTableRole
, Immutable
, NamedFromClause
, FromClause
, AnonymizedFromClauseRole
, StrictFromClauseRole
, FromClauseRole
, ColumnsClauseRole
, JoinTargetRole
, AllowsLambdaRole
):
Class Variable | uses |
Undocumented |
Class Variable | _post |
Undocumented |
Inherited from Selectable
(via DialectKWArgs
, HasSchemaAttr
, SchemaItem
, SchemaEventTarget
, EventTarget
, TableClause
, DMLTableRole
, Immutable
, NamedFromClause
, FromClause
, AnonymizedFromClauseRole
, StrictFromClauseRole
, FromClauseRole
, ColumnsClauseRole
, JoinTargetRole
, AllowsLambdaRole
, UsesInspection
, ColumnListRole
, StructuralRole
):
Method | corresponding |
Given a :class:`_expression.ColumnElement`, return the exported :class:`_expression.ColumnElement` object from the :attr:`_expression.Selectable.exported_columns` collection of this :class:`_expression... |
Method | lateral |
Return a LATERAL alias of this :class:`_expression.Selectable`. |
Method | replace |
Replace all occurrences of :class:`_expression.FromClause` 'old' with the given :class:`_expression.Alias` object, returning a copy of this :class:`_expression.FromClause`. |
Inherited from ReturnsRows
(via DialectKWArgs
, HasSchemaAttr
, SchemaItem
, SchemaEventTarget
, EventTarget
, TableClause
, DMLTableRole
, Immutable
, NamedFromClause
, FromClause
, AnonymizedFromClauseRole
, StrictFromClauseRole
, FromClauseRole
, ColumnsClauseRole
, JoinTargetRole
, AllowsLambdaRole
, UsesInspection
, ColumnListRole
, StructuralRole
, Selectable
):
Property | selectable |
Undocumented |
Class Variable | _is |
Undocumented |
Class Variable | _is |
Undocumented |
Class Variable | _is |
Undocumented |
Class Variable | _is |
Undocumented |
Property | _all |
A sequence of column expression objects that represents the "selected" columns of this :class:`_expression.ReturnsRows`. |
Inherited from DQLDMLClauseElement
(via DialectKWArgs
, HasSchemaAttr
, SchemaItem
, SchemaEventTarget
, EventTarget
, TableClause
, DMLTableRole
, Immutable
, NamedFromClause
, FromClause
, AnonymizedFromClauseRole
, StrictFromClauseRole
, FromClauseRole
, ColumnsClauseRole
, JoinTargetRole
, AllowsLambdaRole
, UsesInspection
, ColumnListRole
, StructuralRole
, Selectable
, ReturnsRows
, ReturnsRowsRole
, SQLRole
):
Method | compile |
Compile this SQL expression. |
Method | _compiler |
Return a compiler appropriate for this ClauseElement, given a Dialect. |
Inherited from ClauseElement
(via DialectKWArgs
, HasSchemaAttr
, SchemaItem
, SchemaEventTarget
, EventTarget
, TableClause
, DMLTableRole
, Immutable
, NamedFromClause
, FromClause
, AnonymizedFromClauseRole
, StrictFromClauseRole
, FromClauseRole
, ColumnsClauseRole
, JoinTargetRole
, AllowsLambdaRole
, UsesInspection
, ColumnListRole
, StructuralRole
, Selectable
, ReturnsRows
, ReturnsRowsRole
, SQLRole
, DQLDMLClauseElement
):
Method | __bool__ |
Undocumented |
Method | __getstate__ |
Undocumented |
Method | __invert__ |
Undocumented |
Method | compare |
Compare this :class:`_expression.ClauseElement` to the given :class:`_expression.ClauseElement`. |
Method | get |
Return immediate child :class:`.visitors.HasTraverseInternals` elements of this :class:`.visitors.HasTraverseInternals`. |
Class Variable | is |
Undocumented |
Class Variable | is |
Undocumented |
Class Variable | negation |
Undocumented |
Method | _cloned |
Return the set consisting all cloned ancestors of this ClauseElement. |
Method | _compile |
Undocumented |
Method | _execute |
Undocumented |
Method | _execute |
an additional hook for subclasses to provide a different implementation for connection.scalar() vs. connection.execute(). |
Method | _negate |
Undocumented |
Method | _negate |
a hook to allow the right side of a binary expression to respond to a negation of the binary expression. |
Method | _replace |
Undocumented |
Method | _set |
Undocumented |
Method | _ungroup |
Return this :class:`_expression.ClauseElement` without any groupings. |
Method | _with |
in the context of binary expression, convert the type of this object to the one given. |
Class Variable | _cache |
Undocumented |
Class Variable | _gen |
Undocumented |
Class Variable | _is |
Undocumented |
Class Variable | _is |
Undocumented |
Class Variable | _is |
Undocumented |
Class Variable | _is |
Undocumented |
Class Variable | _is |
Undocumented |
Class Variable | _is |
Undocumented |
Class Variable | _is |
Undocumented |
Class Variable | _is |
Undocumented |
Class Variable | _is |
Undocumented |
Class Variable | _is |
Undocumented |
Class Variable | _is |
Undocumented |
Instance Variable | _propagate |
like annotations, however these propagate outwards liberally as SQL constructs are built, and are set up at construction time. |
Property | _constructor |
return the 'constructor' for this ClauseElement. |
Property | _order |
Undocumented |
Inherited from SupportsWrappingAnnotations
(via DialectKWArgs
, HasSchemaAttr
, SchemaItem
, SchemaEventTarget
, EventTarget
, TableClause
, DMLTableRole
, Immutable
, NamedFromClause
, FromClause
, AnonymizedFromClauseRole
, StrictFromClauseRole
, FromClauseRole
, ColumnsClauseRole
, JoinTargetRole
, AllowsLambdaRole
, UsesInspection
, ColumnListRole
, StructuralRole
, Selectable
, ReturnsRows
, ReturnsRowsRole
, SQLRole
, DQLDMLClauseElement
, ClauseElement
):
Method | _annotate |
return a copy of this ClauseElement with annotations updated by the given dictionary. |
Method | _deannotate |
return a copy of this :class:`_expression.ClauseElement` with annotations removed. |
Method | _with |
return a copy of this ClauseElement with annotations replaced by the given dictionary. |
Inherited from SupportsAnnotations
(via DialectKWArgs
, HasSchemaAttr
, SchemaItem
, SchemaEventTarget
, EventTarget
, TableClause
, DMLTableRole
, Immutable
, NamedFromClause
, FromClause
, AnonymizedFromClauseRole
, StrictFromClauseRole
, FromClauseRole
, ColumnsClauseRole
, JoinTargetRole
, AllowsLambdaRole
, UsesInspection
, ColumnListRole
, StructuralRole
, Selectable
, ReturnsRows
, ReturnsRowsRole
, SQLRole
, DQLDMLClauseElement
, ClauseElement
, SupportsWrappingAnnotations
):
Class Variable | proxy |
Undocumented |
Method | _gen |
Undocumented |
Property | _annotations |
Undocumented |
Inherited from MemoizedHasCacheKey
(via DialectKWArgs
, HasSchemaAttr
, SchemaItem
, SchemaEventTarget
, EventTarget
, TableClause
, DMLTableRole
, Immutable
, NamedFromClause
, FromClause
, AnonymizedFromClauseRole
, StrictFromClauseRole
, FromClauseRole
, ColumnsClauseRole
, JoinTargetRole
, AllowsLambdaRole
, UsesInspection
, ColumnListRole
, StructuralRole
, Selectable
, ReturnsRows
, ReturnsRowsRole
, SQLRole
, DQLDMLClauseElement
, ClauseElement
, SupportsWrappingAnnotations
, SupportsAnnotations
):
Method | _generate |
return a cache key. |
Inherited from HasCacheKey
(via DialectKWArgs
, HasSchemaAttr
, SchemaItem
, SchemaEventTarget
, EventTarget
, TableClause
, DMLTableRole
, Immutable
, NamedFromClause
, FromClause
, AnonymizedFromClauseRole
, StrictFromClauseRole
, FromClauseRole
, ColumnsClauseRole
, JoinTargetRole
, AllowsLambdaRole
, UsesInspection
, ColumnListRole
, StructuralRole
, Selectable
, ReturnsRows
, ReturnsRowsRole
, SQLRole
, DQLDMLClauseElement
, ClauseElement
, SupportsWrappingAnnotations
, SupportsAnnotations
, MemoizedHasCacheKey
):
Class Variable | inherit |
Indicate if this :class:`.HasCacheKey` instance should make use of the cache key generation scheme used by its immediate superclass. |
Class Method | _generate |
generate cache key dispatcher for a new class. |
Class Method | _generate |
Undocumented |
Class Variable | _generated |
Undocumented |
Class Variable | _hierarchy |
private attribute which may be set to False to prevent the inherit_cache warning from being emitted for a hierarchy of subclasses. |
Class Variable | _is |
Undocumented |
Inherited from CompilerElement
(via DialectKWArgs
, HasSchemaAttr
, SchemaItem
, SchemaEventTarget
, EventTarget
, TableClause
, DMLTableRole
, Immutable
, NamedFromClause
, FromClause
, AnonymizedFromClauseRole
, StrictFromClauseRole
, FromClauseRole
, ColumnsClauseRole
, JoinTargetRole
, AllowsLambdaRole
, UsesInspection
, ColumnListRole
, StructuralRole
, Selectable
, ReturnsRows
, ReturnsRowsRole
, SQLRole
, DQLDMLClauseElement
, ClauseElement
, SupportsWrappingAnnotations
, SupportsAnnotations
, MemoizedHasCacheKey
, HasCacheKey
, HasCopyInternals
, ExternallyTraversible
, HasTraverseInternals
):
Class Variable | stringify |
Undocumented |
Class Variable | supports |
Undocumented |
Inherited from Visitable
(via DialectKWArgs
, HasSchemaAttr
, SchemaItem
, SchemaEventTarget
, EventTarget
, TableClause
, DMLTableRole
, Immutable
, NamedFromClause
, FromClause
, AnonymizedFromClauseRole
, StrictFromClauseRole
, FromClauseRole
, ColumnsClauseRole
, JoinTargetRole
, AllowsLambdaRole
, UsesInspection
, ColumnListRole
, StructuralRole
, Selectable
, ReturnsRows
, ReturnsRowsRole
, SQLRole
, DQLDMLClauseElement
, ClauseElement
, SupportsWrappingAnnotations
, SupportsAnnotations
, MemoizedHasCacheKey
, HasCacheKey
, HasCopyInternals
, ExternallyTraversible
, HasTraverseInternals
, CompilerElement
):
Method | __class |
Undocumented |
Method | __init |
Undocumented |
Class Method | _generate |
Undocumented |
Method | _compiler |
Undocumented |
Class Variable | _original |
Undocumented |
str
, metadata: MetaData
, *args: SchemaItem
, schema: Optional[ Union[ str, Literal[ SchemaConst.BLANK_SCHEMA]]]
= None, quote: Optional[ bool]
= None, quote_schema: Optional[ bool]
= None, autoload_with: Optional[ Union[ Engine, Connection]]
= None, autoload_replace: bool
= True, keep_existing: bool
= False, extend_existing: bool
= False, resolve_fks: bool
= True, include_columns: Optional[ Collection[ str]]
= None, implicit_returning: bool
= True, comment: Optional[ str]
= None, info: Optional[ Dict[ Any, Any]]
= None, listeners: Optional[ _typing_Sequence[ Tuple[ str, Callable[ ..., Any]]]]
= None, prefixes: Optional[ _typing_Sequence[ str]]
= None, _extend_on: Optional[ Set[ Table]]
= None, _no_init: bool
= True, **kw: Any
):
(source)
¶
Constructor for :class:`_schema.Table`. :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:`_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 unless they are a reserved word or contain special characters. A name with any number of upper case characters is considered to be case sensitive, and will be sent as quoted. To enable unconditional quoting for the table name, specify the flag ``quote=True`` to the constructor, or use the :class:`.quoted_name` construct to specify the name. :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:`.Connection` or :class:`.Engine`. :param \*args: Additional positional arguments are used primarily 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:`_schema.ForeignKeyConstraint`. :param autoload_replace: Defaults to ``True``; when using :paramref:`_schema.Table.autoload_with` 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:`_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:`_schema.Table.extend_existing` is ``True``. .. seealso:: :paramref:`_schema.Table.autoload_with` :paramref:`_schema.Table.extend_existing` :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, the autoload process will take place for this table against the given engine or connection. :param extend_existing: When ``True``, indicates that if this :class:`_schema.Table` is already present in the given :class:`_schema.MetaData`, apply further arguments within the constructor to the existing :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:`_schema.Table` is specified that matches an existing :class:`_schema.Table`, yet specifies additional constructs. :paramref:`_schema.Table.extend_existing` will also work in conjunction with :paramref:`_schema.Table.autoload_with` 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:`_schema.MetaData`; newly reflected :class:`_schema.Column` objects and other options will be added into the state of the :class:`_schema.Table`, potentially overwriting existing columns and options of the same name. As is always the case with :paramref:`_schema.Table.autoload_with`, :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:`_schema.Column` objects both reflected from the database, as well as the given :class:`_schema.Column` named "y":: Table("mytable", metadata, Column('y', Integer), extend_existing=True, autoload_with=engine ) .. seealso:: :paramref:`_schema.Table.autoload_with` :paramref:`_schema.Table.autoload_replace` :paramref:`_schema.Table.keep_existing` :param implicit_returning: True by default - indicates that RETURNING can be used, typically by the ORM, in order to fetch server-generated values such as primary key values and server side defaults, on those backends which support RETURNING. In modern SQLAlchemy there is generally no reason to alter this setting, except for some backend specific cases (see :ref:`mssql_triggers` in the SQL Server dialect documentation for one such example). :param include_columns: A list of strings indicating a subset of columns to be loaded via the ``autoload`` operation; table columns who aren't present in this list will not be represented on the resulting ``Table`` object. Defaults to ``None`` which indicates all columns should be reflected. :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_with` is specified. Defaults to True. Set to False to disable reflection of 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:`_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 .. seealso:: :paramref:`.MetaData.reflect.resolve_fks` :param info: Optional data dictionary which will be populated into the :attr:`.SchemaItem.info` attribute of this object. :param keep_existing: When ``True``, indicates that if this Table is already present in the given :class:`_schema.MetaData`, ignore further arguments within the constructor to the existing :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:`_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:`_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:`_schema.Table` is specified that matches an existing :class:`_schema.Table`, yet specifies additional constructs. .. seealso:: :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:`_schema.Table` before the "autoload" process begins. Historically this has been intended for use with the :meth:`.DDLEvents.column_reflect` event, however note that this event hook may now be associated with the :class:`_schema.MetaData` object directly:: def listen_for_reflect(table, column_info): "handle the column reflection event" # ... t = Table( 'sometable', autoload_with=engine, listeners=[ ('column_reflect', listen_for_reflect) ]) .. seealso:: :meth:`_events.DDLEvents.column_reflect` :param must_exist: When ``True``, indicates that this Table must already be present in the given :class:`_schema.MetaData` collection, else an exception is raised. :param prefixes: A list of strings to insert after CREATE in the CREATE TABLE statement. They will be separated by spaces. :param quote: Force quoting of this table's name on or off, corresponding to ``True`` or ``False``. When left at its default of ``None``, the column identifier will be quoted according to whether the name is case sensitive (identifiers with at least one upper case character are treated as case sensitive), or if it's a reserved word. This flag is only needed to force quoting of a reserved word which is not known by the SQLAlchemy dialect. .. note:: setting this flag to ``False`` will not provide case-insensitive behavior for table reflection; table reflection will always search for a mixed-case name in a case sensitive fashion. Case insensitive names are specified in SQLAlchemy only by stating the name with all lower case characters. :param quote_schema: same as 'quote' but applies to the schema identifier. :param schema: The schema name for this table, which is required if 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:`_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:`_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 case-sensitive names; to enable unconditional quoting for the schema name, specify the flag ``quote_schema=True`` to the constructor, or use the :class:`.quoted_name` construct to specify the name. :param comment: Optional string that will render an SQL comment on table creation. .. 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>``. See the documentation regarding an individual dialect at :ref:`dialect_toplevel` for detail on documented arguments.
def __new__(cls, *args:
Any
, **kw: Any
) -> Any
:
(source)
¶
Undocumented
Add a 'dependency' for this Table. This is another Table object which must be created first before this one can, or dropped after this one. Usually, dependencies between tables are determined via ForeignKey objects. However, for other situations that create dependencies outside of foreign keys (rules, inheriting), this method can manually establish such a link.
Append a :class:`_schema.Column` to this :class:`_schema.Table`. 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 column definition will be included in any CREATE TABLE, SELECT, UPDATE, etc. statements generated from this :class:`_schema.Table` construct. Note that this does **not** change the definition of the table as it exists within any underlying database, assuming that table has already been created in the database. Relational databases support the addition of columns to existing tables using the SQL ALTER command, which would need to be emitted for an already-existing table that doesn't contain the newly added column. :param replace_existing: When ``True``, allows replacing existing columns. When ``False``, the default, an warning will be raised if a column with the same ``.key`` already exists. A future version of sqlalchemy will instead rise a warning. .. versionadded:: 1.4.0
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. Note that this does **not** produce the constraint within the relational database automatically, for a table that already exists in the database. To add a constraint to an existing relational database table, the SQL ALTER command must be used. SQLAlchemy also provides the :class:`.AddConstraint` construct which can produce this SQL when invoked as an executable clause.
Issue a ``CREATE`` statement for this :class:`_schema.Table`, using the given :class:`.Connection` or :class:`.Engine` for connectivity. .. seealso:: :meth:`_schema.MetaData.create_all`.
Issue a ``DROP`` statement for this :class:`_schema.Table`, using the given :class:`.Connection` or :class:`.Engine` for connectivity. .. seealso:: :meth:`_schema.MetaData.drop_all`.
MetaData
, schema: Union[ str, Literal[ SchemaConst.RETAIN_SCHEMA]]
= RETAIN_SCHEMA, referred_schema_fn: Optional[ Callable[ [ Table, Optional[ str], ForeignKeyConstraint, Optional[ str]], Optional[ str]]]
= None, name: Optional[ str]
= None) -> Table
:
(source)
¶
Return a copy of this :class:`_schema.Table` associated with a different :class:`_schema.MetaData`. E.g.:: m1 = MetaData() user = Table('user', m1, Column('id', Integer, primary_key=True)) m2 = MetaData() user_copy = user.to_metadata(m2) .. versionchanged:: 1.4 The :meth:`_schema.Table.to_metadata` function was renamed from :meth:`_schema.Table.tometadata`. :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:`_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:`_schema.MetaData`, which is typically ``None`` as well, unless set explicitly:: m2 = MetaData(schema='newschema') # user_copy_one will have "newschema" as the schema name user_copy_one = user.to_metadata(m2, schema=None) m3 = MetaData() # schema defaults to None # user_copy_two will have None as the schema name user_copy_two = user.to_metadata(m3, schema=None) :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:`_schema.ForeignKeyConstraint`. The callable accepts this parent :class:`_schema.Table`, the target schema that we are changing to, the :class:`_schema.ForeignKeyConstraint` object, and the existing "target schema" of that constraint. The function should return the string schema name that should be applied. To reset the schema to "none", return the symbol :data:`.BLANK_SCHEMA`. To effect no change, return ``None`` or :data:`.RETAIN_SCHEMA`. .. versionchanged:: 1.4.33 The ``referred_schema_fn`` function may return the :data:`.BLANK_SCHEMA` or :data:`.RETAIN_SCHEMA` symbols. E.g.:: def referred_schema_fn(table, to_schema, constraint, referred_schema): if referred_schema == 'base_tables': return referred_schema else: return to_schema new_table = table.to_metadata(m2, schema="alt_schema", referred_schema_fn=referred_schema_fn) .. versionadded:: 0.9.2 :param name: optional string name indicating the target table name. If not specified or None, the table name is retained. This allows a :class:`_schema.Table` to be copied to the same :class:`_schema.MetaData` target with a new name. .. versionadded:: 1.0.0
def tometadata(self, metadata:
MetaData
, schema: Union[ str, Literal[ SchemaConst.RETAIN_SCHEMA]]
= RETAIN_SCHEMA, referred_schema_fn: Optional[ Callable[ [ Table, Optional[ str], ForeignKeyConstraint, Optional[ str]], Optional[ str]]]
= None, name: Optional[ str]
= None) -> Table
:
(source)
¶
Return a copy of this :class:`_schema.Table` associated with a different :class:`_schema.MetaData`. See :meth:`_schema.Table.to_metadata` for a full description.
A collection of all :class:`_schema.Constraint` objects associated with this :class:`_schema.Table`. Includes :class:`_schema.PrimaryKeyConstraint`, :class:`_schema.ForeignKeyConstraint`, :class:`_schema.UniqueConstraint`, :class:`_schema.CheckConstraint`. A separate collection :attr:`_schema.Table.foreign_key_constraints` refers to the collection of all :class:`_schema.ForeignKeyConstraint` objects, and the :attr:`_schema.Table.primary_key` attribute refers to the single :class:`_schema.PrimaryKeyConstraint` associated with the :class:`_schema.Table`. .. seealso:: :attr:`_schema.Table.constraints` :attr:`_schema.Table.primary_key` :attr:`_schema.Table.foreign_key_constraints` :attr:`_schema.Table.indexes` :class:`_reflection.Inspector`
Return the collection of :class:`_schema.ForeignKey` marker objects which this FromClause references. Each :class:`_schema.ForeignKey` is a member of a :class:`_schema.Table`-wide :class:`_schema.ForeignKeyConstraint`. .. seealso:: :attr:`_schema.Table.foreign_key_constraints`
:class:`_expression.TableClause` doesn't support having a primary key or column -level defaults, so implicit returning doesn't apply.
A collection of all :class:`_schema.Index` objects associated with this :class:`_schema.Table`. .. seealso:: :meth:`_reflection.Inspector.get_indexes`
sqlalchemy.sql.schema.SchemaItem.info
Info dictionary associated with the object, allowing user-defined data to be associated with this :class:`.SchemaItem`. The dictionary is automatically generated when first accessed. It can also be specified in the constructor of some objects, such as :class:`_schema.Table` and :class:`_schema.Column`.
Define the 'schema' attribute for this :class:`_expression.FromClause`. This is typically ``None`` for most objects except that of :class:`_schema.Table`, where it is taken as the value of the :paramref:`_schema.Table.schema` argument.
Returns the :class:`.Column` object which currently represents the "auto increment" column, if any, else returns None. This is based on the rules for :class:`.Column` as defined by the :paramref:`.Column.autoincrement` parameter, which generally means the column within a single integer column primary key constraint that is not constrained by a foreign key. If the table does not have such a primary key constraint, then there's no "autoincrement" column. A :class:`.Table` may have only one column defined as the "autoincrement" column. .. versionadded:: 2.0.4 .. seealso:: :paramref:`.Column.autoincrement`
sqlalchemy.sql.selectable.TableClause.c
A synonym for :attr:`.FromClause.columns` :return: a :class:`.ColumnCollection`
A named-based collection of :class:`_expression.ColumnElement` objects maintained by this :class:`_expression.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) :return: a :class:`.ColumnCollection` object.
exported_columns:
ReadOnlyColumnCollection[ str, Column[ Any]]
=
(source)
¶
A :class:`_expression.ColumnCollection` that represents the "exported" columns of this :class:`_expression.Selectable`. The "exported" columns for a :class:`_expression.FromClause` object are synonymous with the :attr:`_expression.FromClause.columns` collection. .. versionadded:: 1.4 .. seealso:: :attr:`_expression.Selectable.exported_columns` :attr:`_expression.SelectBase.exported_columns`
:class:`_schema.ForeignKeyConstraint` objects referred to by this :class:`_schema.Table`. This list is produced from the collection of :class:`_schema.ForeignKey` objects currently associated. .. seealso:: :attr:`_schema.Table.constraints` :attr:`_schema.Table.foreign_keys` :attr:`_schema.Table.indexes`
Return the 'key' for this :class:`_schema.Table`. This value is used as the dictionary key within the :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``.
Return the iterable collection of :class:`_schema.Column` objects which comprise the primary key of this :class:`_selectable.FromClause`. For a :class:`_schema.Table` object, this collection is represented by the :class:`_schema.PrimaryKeyConstraint` which itself is an iterable collection of :class:`_schema.Column` objects.
MetaData
, autoload_with: Union[ Engine, Connection]
, include_columns: Optional[ Collection[ str]]
, exclude_columns: Collection[ str]
= (), resolve_fks: bool
= True, _extend_on: Optional[ Set[ Table]]
= None, _reflect_info: _ReflectionInfo|None
= None):
(source)
¶
Undocumented
anon_map
, bindparams: List[ BindParameter[ Any]]
) -> Tuple[ Any, ...]
:
(source)
¶
return an optional cache key. The cache key is a tuple which can contain any series of objects that are hashable and also identifies this object uniquely within the presence of a larger SQL expression or statement, for the purposes of caching the resulting query. The cache key should be based on the SQL compiled structure that would ultimately be produced. That is, two structures that are composed in exactly the same way should produce the same cache key; any difference in the structures that would affect the SQL string or the type handlers should result in a different cache key. If a structure cannot produce a useful cache key, the NO_CACHE symbol should be added to the anon_map and the method should return None.