aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/clickhouse-connect/clickhouse_connect/cc_sqlalchemy/sql/__init__.py
blob: 00b9bc8c134fdce2f203edf7363b358ea108d9bb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from typing import Optional

from sqlalchemy import Table

from clickhouse_connect.driver.binding import quote_identifier


def full_table(table_name: str, schema: Optional[str] = None) -> str:
    if table_name.startswith('(') or '.' in table_name or not schema:
        return quote_identifier(table_name)
    return f'{quote_identifier(schema)}.{quote_identifier(table_name)}'


def format_table(table: Table):
    return full_table(table.name, table.schema)