clickhouse-sqlalchemy
clickhouse-sqlalchemy copied to clipboard
how to create a class ORM relate with postgres table
Usually, create a ORM class as below:
from sqlalchemy import Column
from clickhouse_sqlalchemy.ext.declarative import declarative_base
ChBase = declarative_base()
class TbFile(ChBase):
__tablename__ = 'tb_file'
__table_args__ = {'comment': 'File Info Table V2.0'}
created = Column(types.DateTime, server_default=F.now())
filename = Column(types.String, primary_key=True)
id = Column(types.UInt32)
__table_args__ = (
engines.MergeTree(order_by='id', primary_key='id'),
)
but if I want to use clickhouse to interact with a relational database table(for example postgres table) how to create it?
From this webpage, we can get the raw sql mehod to do it.
https://clickhouse.com/docs/zh/engines/database-engines/postgresql/
CREATE DATABASE test_database
ENGINE = PostgreSQL('host:port', 'database', 'user', 'password'[, use_table_cache
]);
SELECT * FROM test_database.test_table;
INSERT INTO test_database.test_table VALUES (3,4);