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 :

Vous êtes un professionnel et vous avez besoin d'une formation ? Machine Learning
avec Scikit-Learn
Voir le programme détaillé
Classe « Table »

Méthode sqlalchemy.Table.to_metadata

Signature de la méthode to_metadata

def to_metadata(self, metadata: 'MetaData', schema: 'Union[str, Literal[SchemaConst.RETAIN_SCHEMA]]' = <SchemaConst.RETAIN_SCHEMA: 1>, referred_schema_fn: 'Optional[Callable[[Table, Optional[str], ForeignKeyConstraint, Optional[str]], Optional[str]]]' = None, name: 'Optional[str]' = None) -> 'Table' 

Description

help(Table.to_metadata)

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
        )

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



Vous êtes un professionnel et vous avez besoin d'une formation ? Programmation Python
Les compléments
Voir le programme détaillé