Skip to content

Commit

Permalink
Wrap columns_in_query query in select statement
Browse files Browse the repository at this point in the history
  • Loading branch information
ptemarvelde authored Dec 13, 2023
1 parent 5ccdad5 commit 99de430
Show file tree
Hide file tree
Showing 2 changed files with 2 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
2 changes: 1 addition & 1 deletion dbt/adapters/clickhouse/nativeclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ 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 99de430

Please sign in to comment.