Add a column to this :class:`_sql.ColumnCollection`. .. note:: This method is **not normally used by user-facing code**, as the :class:`_sql.ColumnCollection` is usually part of an existing object such as a :class:`_schema.Table`. To add a :c
(
self, column: ColumnElement[Any], key: Optional[_COLKEY] = None
)
| 1812 | self._index.update({k: (k, col) for k, col, _ in reversed(collection)}) |
| 1813 | |
| 1814 | def add( |
| 1815 | self, column: ColumnElement[Any], key: Optional[_COLKEY] = None |
| 1816 | ) -> None: |
| 1817 | """Add a column to this :class:`_sql.ColumnCollection`. |
| 1818 | |
| 1819 | .. note:: |
| 1820 | |
| 1821 | This method is **not normally used by user-facing code**, as the |
| 1822 | :class:`_sql.ColumnCollection` is usually part of an existing |
| 1823 | object such as a :class:`_schema.Table`. To add a |
| 1824 | :class:`_schema.Column` to an existing :class:`_schema.Table` |
| 1825 | object, use the :meth:`_schema.Table.append_column` method. |
| 1826 | |
| 1827 | """ |
| 1828 | colkey: _COLKEY |
| 1829 | |
| 1830 | if key is None: |
| 1831 | colkey = column.key # type: ignore |
| 1832 | else: |
| 1833 | colkey = key |
| 1834 | |
| 1835 | l = len(self._collection) |
| 1836 | |
| 1837 | # don't really know how this part is supposed to work w/ the |
| 1838 | # covariant thing |
| 1839 | |
| 1840 | _column = cast(_COL_co, column) |
| 1841 | |
| 1842 | self._collection.append( |
| 1843 | (colkey, _column, _ColumnMetrics(self, _column)) |
| 1844 | ) |
| 1845 | self._colset.add(_column._deannotate()) |
| 1846 | self._index[l] = (colkey, _column) |
| 1847 | if colkey not in self._index: |
| 1848 | self._index[colkey] = (colkey, _column) |
| 1849 | |
| 1850 | def __getstate__(self) -> Dict[str, Any]: |
| 1851 | return { |