clickhouse-sqlalchemy icon indicating copy to clipboard operation
clickhouse-sqlalchemy copied to clipboard

how to create a class ORM relate with postgres table

Open flyly0755 opened this issue 2 years ago • 0 comments

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);

flyly0755 avatar Dec 06 '22 07:12 flyly0755