🤖 Track your AI apps.
Use our free template.
Back
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
TinybirdTeam

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.

Start building with Tinybird!
If you've read this far, you might want to use Tinybird as your analytics backend. You can just get started, on the free plan.

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

Subscribe to our newsletter
Get 10 links weekly to the Data and AI articles the Tinybird team is reading.
Do you like this post? Spread it!

Related posts

Skip the infra work. Ship your first API today.

Read the docs
Tinybird wordmark