Skip to content

Commit

Permalink
Wrap columns_in_query query in select statement (#222)
Browse files Browse the repository at this point in the history
* Wrap columns_in_query query in select statement

* formatting
  • Loading branch information
ptemarvelde authored Dec 13, 2023
1 parent 5ccdad5 commit 2d5c675
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dbt/adapters/clickhouse/httpclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def command(self, sql, **kwargs):

def columns_in_query(self, sql: str, **kwargs) -> List[ClickHouseColumn]:
try:
query_result = self._client.query(f'{sql} LIMIT 0', **kwargs)
query_result = self._client.query(f"SELECT * FROM ({sql}) 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
4 changes: 3 additions & 1 deletion dbt/adapters/clickhouse/nativeclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ def command(self, sql, **kwargs):

def columns_in_query(self, sql: str, **kwargs) -> List[ClickHouseColumn]:
try:
_, columns = self._client.execute(f'{sql} LIMIT 0', with_column_types=True)
_, columns = self._client.execute(
f"SELECT * FROM ({sql}) LIMIT 0", with_column_types=True
)
return [ClickHouseColumn.create(column[0], column[1]) for column in columns]
except clickhouse_driver.errors.Error as ex:
raise DbtDatabaseError(str(ex).strip()) from ex
Expand Down

0 comments on commit 2d5c675

Please sign in to comment.