Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
- Added `timestamp without time zone` types (scalar and array)
- On SQLAlchemy 2, mapped `real` and `double{_precision}` types to the
newly introduced `sqltypes.{DOUBLE,DOUBLE_PRECISION}` types
- Compiler: Made `CREATE INDEX` a no-op, only emitting `SELECT 1`, because CrateDB
does not support that statement

## 2026/05/28 0.42.0
- Added support for SQL Alchemy 2.1
Expand Down
11 changes: 11 additions & 0 deletions src/sqlalchemy_cratedb/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,17 @@ def visit_unique_constraint(self, constraint, **kw):
)
return

def visit_create_index(self, create, **kw) -> str:
"""
CrateDB does not support `CREATE INDEX` statements.
"""
warnings.warn(
"CrateDB does not support `CREATE INDEX` statements, "
"they will be omitted when generating DDL statements.",
stacklevel=2,
)
return "SELECT 1"


class CrateTypeCompiler(compiler.GenericTypeCompiler):
def visit_string(self, type_, **kw):
Expand Down
32 changes: 32 additions & 0 deletions tests/compiler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,3 +511,35 @@ class FooBar(Base):

"""),
) # noqa: W291, W293

def test_ddl_with_create_index(self):
"""
Verify the CrateDB dialect properly ignores `CREATE INDEX` statements.
"""

Base = declarative_base(metadata=self.metadata)

class FooBar(Base):
"""The entity."""

__tablename__ = "foobar"

id = sa.Column(sa.Integer, primary_key=True)
name = sa.Column(sa.String, index=True)

with warnings.catch_warnings(record=True) as w:
# Cause all warnings to always be triggered.
warnings.simplefilter("always")

# Verify SQL DDL statement.
self.metadata.create_all(self.engine, tables=[FooBar.__table__], checkfirst=False)
self.assertEqual(self.executed_statement, "SELECT 1")

# Verify if corresponding warning is emitted.
self.assertEqual(len(w), 1)
self.assertIsSubclass(w[-1].category, UserWarning)
self.assertIn(
"CrateDB does not support `CREATE INDEX` statements, "
"they will be omitted when generating DDL statements.",
str(w[-1].message),
)