-
-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
method xxx.__table__.create(engine) failed when create view which raise error "sqlalchemy.exc.CompileError: No engine for table 'xxx'" #261
Comments
from sqlalchemy import create_engine, Column, MetaData, text
from clickhouse_sqlalchemy import (
Table, make_session, get_declarative_base, types, engines, MaterializedView, select
)
uri = 'clickhouse://default:@localhost/default'
engine = create_engine(uri)
session = make_session(engine)
metadata = MetaData()
Base = get_declarative_base(metadata=metadata)
class TableTest(Base):
__tablename__ = 'tabletest'
id = Column(types.Int8, primary_key=True)
testcontent = Column(types.String)
remark = Column(types.String)
__table_args__ = (
engines.MergeTree(order_by='id', primary_key='id'),
{'comment': 'table used for testing'}
)
class ViewTest(Base):
__tablename__ = 'viewTest'
id = Column(types.Int8, primary_key=True)
testcontent = Column(types.String)
remark = Column(types.String)
__table_args__ = (
engines.MergeTree(order_by='id', primary_key='id'),
# Comments are not supported for mat view {'comment': 'view used for testing'}
# No COMMENT clause here https://clickhouse.com/docs/en/sql-reference/statements/create/view#materialized-view
)
MatView = MaterializedView(ViewTest, select(
TableTest.id.label('id'),
TableTest.testcontent.label('testcontent'),
TableTest.remark.label('remark'),
))
TableTest.__table__.create(bind=engine)
MatView.create(bind=engine) |
@xzkostyan Thank you so much, and I have another doubt, which means only support orm manner to create MaterializedView? |
I don't understand what do you want. |
@xzkostyan |
Describe the bug
Use code below to create table and view.
TableTest.table.create(engine) # success create table tableTest
ViewTest.table.create(engine) # raise error sqlalchemy.exc.CompileError: No engine for table 'viewTest'
Base.metadata.create_all(bind=engine) # success create both table tableTest and view viewTest
To Reproduce
Expected behavior
ViewTest.__table__.create(engine) can create view viewTest successfully.
Maybe xxxt.__table__.create(engine) doesn't support view creation, then how to create one single database view with ORM class?
Versions
python 3.9.11
clickhouse-sqlalchemy==0.2.3
SQLAlchemy==1.4.8
SQLAlchemy-Utils==0.37.8
The text was updated successfully, but these errors were encountered: