Skip to content

Commit

Permalink
fix(clients): add newlines around subquery when retrieving columns to…
Browse files Browse the repository at this point in the history
… avoid a syntax error (#262)
  • Loading branch information
tevariou authored Apr 8, 2024
1 parent ef350a4 commit 08cee87
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 6 additions & 1 deletion dbt/adapters/clickhouse/httpclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ def command(self, sql, **kwargs):

def columns_in_query(self, sql: str, **kwargs) -> List[ClickHouseColumn]:
try:
query_result = self._client.query(f"SELECT * FROM ({sql}) LIMIT 0", **kwargs)
query_result = self._client.query(
f"SELECT * FROM ( \n"
f"{sql} \n"
f") LIMIT 0",
**kwargs,
)
return [
ClickHouseColumn.create(name, ch_type.name)
for name, ch_type in zip(query_result.column_names, query_result.column_types)
Expand Down
5 changes: 4 additions & 1 deletion dbt/adapters/clickhouse/nativeclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ def command(self, sql, **kwargs):
def columns_in_query(self, sql: str, **kwargs) -> List[ClickHouseColumn]:
try:
_, columns = self._client.execute(
f"SELECT * FROM ({sql}) LIMIT 0", with_column_types=True
f"SELECT * FROM ( \n"
f"{sql} \n"
f") LIMIT 0",
with_column_types=True,
)
return [ClickHouseColumn.create(column[0], column[1]) for column in columns]
except clickhouse_driver.errors.Error as ex:
Expand Down

0 comments on commit 08cee87

Please sign in to comment.