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 ? Mise en oeuvre d'IHM
avec Qt et PySide6
Voir le programme détaillé
Module « sqlalchemy »

Classe « ColumnCollection »

Informations générales

Héritage

builtins.object
    Generic
        ColumnCollection

Définition

class ColumnCollection(Generic):

help(ColumnCollection)

Collection of :class:`_expression.ColumnElement` instances,
typically for
:class:`_sql.FromClause` objects.

The :class:`_sql.ColumnCollection` object is most commonly available
as the :attr:`_schema.Table.c` or :attr:`_schema.Table.columns` collection
on the :class:`_schema.Table` object, introduced at
:ref:`metadata_tables_and_columns`.

The :class:`_expression.ColumnCollection` has both mapping- and sequence-
like behaviors. A :class:`_expression.ColumnCollection` usually stores
:class:`_schema.Column` objects, which are then accessible both via mapping
style access as well as attribute access style.

To access :class:`_schema.Column` objects using ordinary attribute-style
access, specify the name like any other object attribute, such as below
a column named ``employee_name`` is accessed::

    >>> employee_table.c.employee_name

To access columns that have names with special characters or spaces,
index-style access is used, such as below which illustrates a column named
``employee ' payment`` is accessed::

    >>> employee_table.c["employee ' payment"]

As the :class:`_sql.ColumnCollection` object provides a Python dictionary
interface, common dictionary method names like
:meth:`_sql.ColumnCollection.keys`, :meth:`_sql.ColumnCollection.values`,
and :meth:`_sql.ColumnCollection.items` are available, which means that
database columns that are keyed under these names also need to use indexed
access::

    >>> employee_table.c["values"]


The name for which a :class:`_schema.Column` would be present is normally
that of the :paramref:`_schema.Column.key` parameter.  In some contexts,
such as a :class:`_sql.Select` object that uses a label style set
using the :meth:`_sql.Select.set_label_style` method, a column of a certain
key may instead be represented under a particular label name such
as ``tablename_columnname``::

    >>> from sqlalchemy import select, column, table
    >>> from sqlalchemy import LABEL_STYLE_TABLENAME_PLUS_COL
    >>> t = table("t", column("c"))
    >>> stmt = select(t).set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL)
    >>> subq = stmt.subquery()
    >>> subq.c.t_c
    <sqlalchemy.sql.elements.ColumnClause at 0x7f59dcf04fa0; t_c>

:class:`.ColumnCollection` also indexes the columns in order and allows
them to be accessible by their integer position::

    >>> cc[0]
    Column('x', Integer(), table=None)
    >>> cc[1]
    Column('y', Integer(), table=None)

.. versionadded:: 1.4 :class:`_expression.ColumnCollection`
   allows integer-based
   index access to the collection.

Iterating the collection yields the column expressions in order::

    >>> list(cc)
    [Column('x', Integer(), table=None),
     Column('y', Integer(), table=None)]

The base :class:`_expression.ColumnCollection` object can store
duplicates, which can
mean either two columns with the same key, in which case the column
returned by key  access is **arbitrary**::

    >>> x1, x2 = Column("x", Integer), Column("x", Integer)
    >>> cc = ColumnCollection(columns=[(x1.name, x1), (x2.name, x2)])
    >>> list(cc)
    [Column('x', Integer(), table=None),
     Column('x', Integer(), table=None)]
    >>> cc["x"] is x1
    False
    >>> cc["x"] is x2
    True

Or it can also mean the same column multiple times.   These cases are
supported as :class:`_expression.ColumnCollection`
is used to represent the columns in
a SELECT statement which may include duplicates.

A special subclass :class:`.DedupeColumnCollection` exists which instead
maintains SQLAlchemy's older behavior of not allowing duplicates; this
collection is used for schema level objects like :class:`_schema.Table`
and
:class:`.PrimaryKeyConstraint` where this deduping is helpful.  The
:class:`.DedupeColumnCollection` class also has additional mutation methods
as the schema constructs have more use cases that require removal and
replacement of columns.

.. versionchanged:: 1.4 :class:`_expression.ColumnCollection`
   now stores duplicate
   column keys as well as the same column in multiple positions.  The
   :class:`.DedupeColumnCollection` class is added to maintain the
   former behavior in those cases where deduplication as well as
   additional replace/remove operations are needed.


Constructeur(s)

Signature du constructeur Description
__init__(self, columns: 'Optional[Iterable[Tuple[_COLKEY, _COL_co]]]' = None)

Liste des opérateurs

Signature de l'opérateur Description
__contains__(self, key: 'str') -> 'bool'
__delitem__(self, key: 'str') -> 'NoReturn'
__eq__(self, other: 'Any') -> 'bool'
__getitem__(self, key: 'Union[str, int, slice, Tuple[Union[str, int], ...]]') -> 'Union[ReadOnlyColumnCollection[_COLKEY, _COL_co], _COL_co]'
__setitem__(self, key: 'str', value: 'Any') -> 'NoReturn'

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

__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
__bool__(self) -> 'bool'
__class_getitem__ Parameterizes a generic class. [extrait de __class_getitem__.__doc__]
__clause_element__(self) -> 'ClauseList'
__getattr__(self, key: 'str') -> '_COL_co'
__getstate__(self) -> 'Dict[str, Any]'
__iter__(self) -> 'Iterator[_COL_co]'
__len__(self) -> 'int'
__setattr__(self, key: 'str', obj: 'Any') -> 'NoReturn'
__setstate__(self, state: 'Dict[str, Any]') -> 'None'
__str__(self) -> 'str'
add(self, column: 'ColumnElement[Any]', key: 'Optional[_COLKEY]' = None) -> 'None' Add a column to this :class:`_sql.ColumnCollection`. [extrait de add.__doc__]
as_readonly(self) -> 'ReadOnlyColumnCollection[_COLKEY, _COL_co]' Return a "read only" form of this [extrait de as_readonly.__doc__]
clear(self) -> 'NoReturn' Dictionary clear() is not implemented for [extrait de clear.__doc__]
compare(self, other: 'ColumnCollection[Any, Any]') -> 'bool' Compare this :class:`_expression.ColumnCollection` to another [extrait de compare.__doc__]
contains_column(self, col: 'ColumnElement[Any]') -> 'bool' Checks if a column object exists in this collection [extrait de contains_column.__doc__]
corresponding_column(self, column: '_COL', require_embedded: 'bool' = False) -> 'Optional[Union[_COL, _COL_co]]' Given a :class:`_expression.ColumnElement`, return the exported [extrait de corresponding_column.__doc__]
get(self, key: 'str', default: 'Optional[_COL]' = None) -> 'Optional[Union[_COL_co, _COL]]' Get a :class:`_sql.ColumnClause` or :class:`_schema.Column` object [extrait de get.__doc__]
items(self) -> 'List[Tuple[_COLKEY, _COL_co]]' Return a sequence of (key, column) tuples for all columns in this [extrait de items.__doc__]
keys(self) -> 'List[_COLKEY]' Return a sequence of string key names for all columns in this [extrait de keys.__doc__]
remove(self, column: 'Any') -> 'None'
update(self, iter_: 'Any') -> 'NoReturn' Dictionary update() is not implemented for [extrait de update.__doc__]
values(self) -> 'List[_COL_co]' Return a sequence of :class:`_sql.ColumnClause` or [extrait de values.__doc__]

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

__init_subclass__, __subclasshook__

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

__delattr__, __dir__, __format__, __getattribute__, __hash__, __init_subclass__, __reduce__, __reduce_ex__, __repr__, __sizeof__, __subclasshook__

Vous êtes un professionnel et vous avez besoin d'une formation ? RAG (Retrieval-Augmented Generation)
et Fine Tuning d'un LLM
Voir le programme détaillé