Sep 22, 2021

ClickHouse tips #11: Best way to get query types

A fast and simple solution to know the types returned by a query
Tinybird
Team

There are situations when we might want to retrieve the type of a query, function, aggregation, etc in ClickHouse. This information could be really important when we want to identify and debug an issue.

Checking in the docs of ClickHouse, it seems like using toTypeName(x) would provide all that we need.

But there is a catch. For toTypeName(x) to return the type, first, it will need to execute the query. This can lead to a long response time and we might get duplicated results that we do not care about like in the following example.

SCHEMA > Evolution
Get 10 links weekly to the Data and AI articles the Tinybird team is reading.

So, can we find a better solution? Yes, using DESCRIBE.

DESCRIBE will return the type after evaluating the query, without execution, and will return only one entry per column. Resulting in an incredible performance boost and more simple solution

Do you like this post?

Related posts

ClickHouse Tips #12: Apply Functions to Columns with a Single Call

Tinybird

Team

Sep 29, 2021
A big performance boost, adding columns and more

Tinybird

Team

May 31, 2021
Changelog: BigQuery connector, CLI improvements, Pagination on endpoints and more

Tinybird

Team

Mar 04, 2021
You can now create Materialized Views in the Tinybird UI
ClickHouse Meetup Madrid videos
We launched an open source ClickHouse Knowledge Base

Tinybird

Team

Oct 11, 2022
Changelog #18: High-frequency ingestion, handling NDJSON files and more product enhancements

Tinybird

Team

Feb 01, 2022
ClickHouse tips #6: Filtering data in subqueries to avoid joins
Changelog #15: improved data flow graph, anomaly detection and more

Tinybird

Team

Jun 25, 2021
Tinybird vs. ClickHouse®️: What's the difference?

Build fast data products, faster.

Try Tinybird and bring your data sources together and enable engineers to build with data in minutes. No credit card required, free to get started.
Tinybird is not affiliated with, associated with, or sponsored by ClickHouse, Inc. ClickHouse® is a registered trademark of ClickHouse, Inc.