Participer au site avec un Tip
Rechercher
 

Améliorations / Corrections

Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.

Emplacement :

Description des améliorations :

Module « sqlalchemy »

Classe « Table »

Informations générales

Héritage

        builtins.object
            Traversible
        builtins.object
            HasCopyInternals
    builtins.object
        HasMemoized
    builtins.object
        HasCacheKey
            MemoizedHasCacheKey
    builtins.object
        SupportsAnnotations
            SupportsWrappingAnnotations
        builtins.object
            SQLRole
                ClauseElement
        builtins.object
            SQLRole
                ReturnsRowsRole
                    ReturnsRows
                        Selectable
builtins.object
    SQLRole
        StructuralRole
    builtins.object
        UsesInspection
    builtins.object
        AllowsLambdaRole
            JoinTargetRole
builtins.object
    SQLRole
        ColumnListRole
    builtins.object
        UsesInspection
    builtins.object
        AllowsLambdaRole
            ColumnsClauseRole
                FromClauseRole
                    StrictFromClauseRole
                        AnonymizedFromClauseRole
                            FromClause
                        builtins.object
                            Immutable
        builtins.object
            SQLRole
                StructuralRole
            builtins.object
                UsesInspection
            builtins.object
                AllowsLambdaRole
                    JoinTargetRole
        builtins.object
            SQLRole
                ColumnListRole
            builtins.object
                UsesInspection
            builtins.object
                AllowsLambdaRole
                    ColumnsClauseRole
                        FromClauseRole
                            DMLTableRole
                                TableClause
                        builtins.object
                            Traversible
                        builtins.object
                            SchemaEventTarget
                                SchemaItem
                            builtins.object
                                DialectKWArgs
                                    Table

Définition

class Table(DialectKWArgs, SchemaItem, TableClause):

Description [extrait de Table.__doc__]

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

    Constructor arguments are as follows:

    :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:`.Connectable`.

    :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: 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 objects that were explicitly specified.
        :class:`_schema.Column` and other objects explicitly set on the
        table will replace corresponding reflected objects.

        .. deprecated:: 1.4

            The autoload parameter is deprecated and will be removed in
            version 2.0.  Please use the
            :paramref:`_schema.Table.autoload_with` parameter, passing an
            engine or connection.

        .. seealso::

            :ref:`metadata_reflection_toplevel`

    :param autoload_replace: Defaults to ``True``; when using
        :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:`_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`

            :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` 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`,
        :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`

            :paramref:`_schema.Table.autoload_replace`

            :paramref:`_schema.Table.keep_existing`


    :param implicit_returning: True by default - indicates that
        RETURNING can be used by default to fetch newly inserted primary key
        values, for backends which support this.  Note that
        :func:`_sa.create_engine` also provides an ``implicit_returning``
        flag.

    :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` or
        :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.

    

Constructeur(s)

Signature du constructeur Description
__new__(cls, *args, **kw)
__init__(self, *args, **kw) Constructor for :class:`_schema.Table`. [extrait de __init__.__doc__]

Liste des attributs statiques

Nom de l'attribut Valeur
allows_lambdaTrue
columns<sqlalchemy.util.langhelpers.memoized_property object at 0x7f40cbcba770>
constraintsNone
create_drop_stringify_dialectdefault
description<sqlalchemy.util.langhelpers.memoized_property object at 0x7f40cbcbba30>
dialect_kwargs<sqlalchemy.util.langhelpers.memoized_property object at 0x7f40cbecc6d0>
dialect_options<sqlalchemy.util.langhelpers.memoized_property object at 0x7f40cbece8c0>
dispatch<sqlalchemy.event.base.DDLEventsDispatch object at 0x7f40cbc2af40>
foreign_keys<sqlalchemy.util.langhelpers.memoized_property object at 0x7f40cbcbac20>
implicit_returningFalse
indexesNone
info<sqlalchemy.util.langhelpers.memoized_property object at 0x7f40cbc85d20>
is_clause_elementTrue
is_selectableTrue
named_with_columnTrue
primary_key<sqlalchemy.util.langhelpers.memoized_property object at 0x7f40cbcbb1f0>
schemaNone
stringify_dialectdefault
supports_executionFalse
uses_inspectionTrue

Attributs statiques hérités de la classe TableClause

bind

Liste des propriétés

Nom de la propriétéDescription
bindReturn the connectable associated with this Table. [extrait de __doc__]
c
entity_namespaceReturn a namespace used for name-based access in SQL expressions. [extrait de __doc__]
exported_columnsA :class:`_expression.ColumnCollection` [extrait de __doc__]
foreign_key_constraints:class:`_schema.ForeignKeyConstraint` objects referred to by this [extrait de __doc__]
keyReturn the 'key' for this :class:`_schema.Table`. [extrait de __doc__]
kwargsA synonym for :attr:`.DialectKWArgs.dialect_kwargs`. [extrait de __doc__]
selectable

Propriétés héritées de la classe FromClause

description

Liste des opérateurs

Opérateurs hérités de la classe ClauseElement

__invert__

Liste des opérateurs

Opérateurs hérités de la classe object

__eq__, __ge__, __gt__, __le__, __lt__, __ne__

Liste des méthodes

Toutes les méthodes Méthodes d'instance Méthodes statiques Méthodes dépréciées
Signature de la méthodeDescription
__repr__(self)
__str__(self)
add_is_dependent_on(self, table) Add a 'dependency' for this Table. [extrait de add_is_dependent_on.__doc__]
append_column(self, column, replace_existing=False) Append a :class:`_schema.Column` to this :class:`_schema.Table`. [extrait de append_column.__doc__]
append_constraint(self, constraint) Append a :class:`_schema.Constraint` to this [extrait de append_constraint.__doc__]
create(self, bind=None, checkfirst=False) Issue a ``CREATE`` statement for this [extrait de create.__doc__]
drop(self, bind=None, checkfirst=False) Issue a ``DROP`` statement for this [extrait de drop.__doc__]
exists(self, bind=None) Return True if this table exists. [extrait de exists.__doc__]
to_metadata(self, metadata, schema=symbol('retain_schema'), referred_schema_fn=None, name=None) Return a copy of this :class:`_schema.Table` associated with a [extrait de to_metadata.__doc__]
tometadata(self, metadata, schema=symbol('retain_schema'), referred_schema_fn=None, name=None) Return a copy of this :class:`_schema.Table` [extrait de tometadata.__doc__]

Méthodes héritées de la classe TableClause

__init_subclass__, __subclasshook__, delete, insert, update

Méthodes héritées de la classe FromClause

alias, is_derived_from, join, outerjoin, select, table_valued, tablesample

Méthodes héritées de la classe Selectable

corresponding_column, lateral, replace_selectable

Méthodes héritées de la classe ClauseElement

__bool__, __getstate__, __nonzero__, compare, compile, params, self_group, unique_params

Méthodes héritées de la classe HasMemoized

memoized_attribute, memoized_instancemethod

Méthodes héritées de la classe Traversible

__class_getitem__, get_children

Méthodes héritées de la classe DialectKWArgs

argument_for

Méthodes héritées de la classe object

__delattr__, __dir__, __format__, __getattribute__, __hash__, __reduce__, __reduce_ex__, __setattr__, __sizeof__