sqlalchemy_singlestoredb.ColumnGroup¶
- class sqlalchemy_singlestoredb.ColumnGroup(*, name: str | None = None)¶
SingleStore COLUMN GROUP DDL element.
Represents a COLUMN GROUP constraint that creates a materialized copy of each row as a separate index for columnstore tables, improving full-row retrieval/update on wide tables.
- Parameters:
name (str, optional, keyword-only) – Optional name for the column group. If not provided, SingleStore will auto-generate a name. Must be passed as a keyword argument if specified.
Examples
Column group with name:
>>> ColumnGroup(name='cg_all_columns')
Column group without explicit name (auto-generated):
>>> ColumnGroup()
Table Usage:
from sqlalchemy import Column, Integer, MetaData, String, Table from sqlalchemy_singlestoredb import ColumnGroup, ColumnStore metadata = MetaData() wide_table = Table( 'wide_table', metadata, Column('id', Integer, primary_key=True), Column('col1', String(100)), Column('col2', String(100)), singlestoredb_table_type=ColumnStore(), singlestoredb_column_group=ColumnGroup(name='cg_all'), ) # Column group with auto-generated name analytics = Table( 'analytics', metadata, Column('id', Integer, primary_key=True), Column('data', String(255)), singlestoredb_table_type=ColumnStore(), singlestoredb_column_group=ColumnGroup(), )
ORM Usage:
from sqlalchemy import Column, Integer, String from sqlalchemy.orm import declarative_base from sqlalchemy_singlestoredb import ColumnGroup, ColumnStore Base = declarative_base() class WideTable(Base): __tablename__ = 'wide_table' id = Column(Integer, primary_key=True) col1 = Column(String(100)) col2 = Column(String(100)) __table_args__ = { 'singlestoredb_table_type': ColumnStore(), 'singlestoredb_column_group': ColumnGroup(name='cg_all'), } class Analytics(Base): __tablename__ = 'analytics' id = Column(Integer, primary_key=True) data = Column(String(255)) __table_args__ = { 'singlestoredb_table_type': ColumnStore(), 'singlestoredb_column_group': ColumnGroup(), }
Notes
Only supported on columnstore tables
Automatically applies to all columns (uses * syntax)
Subset column groups are not supported by SingleStore
Improves full-row retrieval/update performance on wide tables
Uses less RAM than rowstore for similar use cases
If name is not provided, SingleStore will auto-generate one
Methods
__init__(*[, name])against(target)Return a copy of this
_schema.ExecutableDDLElementwhich will include the given target.compare(other, **kw)Compare this
_expression.ClauseElementto the given_expression.ClauseElement.compile([bind, dialect])Compile this SQL expression.
execute_if([dialect, callable_, state])Return a callable that will execute this
_ddl.ExecutableDDLElementconditionally within an event handler.execution_options(**kw)Set non-SQL options for the statement which take effect during execution.
get_children(*[, omit_attrs])Return immediate child
visitors.HasTraverseInternalselements of thisvisitors.HasTraverseInternals.get_execution_options()Get the non-SQL options which will take effect during execution.
memoized_instancemethod(fn)Decorate a method memoize its return value.
options(*options)Apply options to this statement.
params([_ClauseElement__optionaldict])Return a copy with
_expression.bindparam()elements replaced.self_group([against])Apply a 'grouping' to this
_expression.ClauseElement.unique_params([_ClauseElement__optionaldict])Return a copy with
_expression.bindparam()elements replaced.Attributes
allows_lambdadescriptionentity_namespaceinherit_cacheIndicate if this
HasCacheKeyinstance should make use of the cache key generation scheme used by its immediate superclass.is_clause_elementis_deleteis_dmlis_from_statementis_insertis_selectis_selectableis_textis_updatestringify_dialectsupports_executiontargetuses_inspectionnamenegation_clauseproxy_set