sqlalchemy_singlestoredb.MultiValueIndex

class sqlalchemy_singlestoredb.MultiValueIndex(*columns: str, index_options: str | Dict[str, Any] | None = None)

SingleStore MULTI VALUE INDEX DDL element.

Represents a MULTI VALUE INDEX for indexing JSON array values, enabling efficient queries on individual array elements.

Parameters:
  • *columns (str) – Variable number of column names to include in the multi-value index. Must be JSON columns.

  • index_options (str or Dict[str, Any], optional, keyword-only) – Index options for the multi-value index. Can be either a JSON string or a dictionary that will be automatically JSON-serialized.

Examples

Basic multi-value index:

>>> MultiValueIndex('tags')

Multiple columns multi-value index:

>>> MultiValueIndex('tags', 'categories')

Multi-value index with options:

>>> MultiValueIndex('tags', index_options={'some_option': 'value'})

Table Usage:

from sqlalchemy import Column, Integer, MetaData, Table
from sqlalchemy_singlestoredb import JSON, MultiValueIndex
metadata = MetaData()
articles = Table(
    'articles', metadata,
    Column('id', Integer, primary_key=True),
    Column('tags', JSON),
    singlestoredb_multi_value_indexes=[MultiValueIndex('tags')],
)
# Multiple columns
products = Table(
    'products', metadata,
    Column('id', Integer, primary_key=True),
    Column('tags', JSON),
    Column('categories', JSON),
    singlestoredb_multi_value_indexes=[
        MultiValueIndex('tags', 'categories'),
    ],
)

ORM Usage:

from sqlalchemy import Column, Integer
from sqlalchemy.orm import declarative_base
from sqlalchemy_singlestoredb import JSON, MultiValueIndex
Base = declarative_base()
class Article(Base):
    __tablename__ = 'articles'
    id = Column(Integer, primary_key=True)
    tags = Column(JSON)
    __table_args__ = {
        'singlestoredb_multi_value_indexes': [MultiValueIndex('tags')],
    }
class Product(Base):
    __tablename__ = 'products'
    id = Column(Integer, primary_key=True)
    tags = Column(JSON)
    categories = Column(JSON)
    __table_args__ = {
        'singlestoredb_multi_value_indexes': [
            MultiValueIndex('tags', 'categories'),
        ],
    }

Notes

Multi-value indexes are used to index JSON arrays in SingleStore. They allow efficient queries on individual elements within JSON arrays. The columns must be of JSON type for multi-value indexing to work properly.

__init__(*columns: str, index_options: str | Dict[str, Any] | None = None) None

Methods

__init__(*columns[, index_options])

against(target)

Return a copy of this _schema.ExecutableDDLElement which will include the given target.

compare(other, **kw)

Compare this _expression.ClauseElement to the given _expression.ClauseElement.

compile([bind, dialect])

Compile this SQL expression.

execute_if([dialect, callable_, state])

Return a callable that will execute this _ddl.ExecutableDDLElement conditionally 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.HasTraverseInternals elements of this visitors.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_lambda

description

entity_namespace

inherit_cache

Indicate if this HasCacheKey instance should make use of the cache key generation scheme used by its immediate superclass.

is_clause_element

is_delete

is_dml

is_from_statement

is_insert

is_select

is_selectable

is_text

is_update

stringify_dialect

supports_execution

target

uses_inspection

columns

index_options

negation_clause

proxy_set