Sep 29, 2021

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

Clickhouse 21 allows some fancy operations packed into multiple columns with SELECT modifiers.
Tinybird
Team

Sometimes we have to apply simple operations in multiple columns and modify the stored/original value of those columns. ClickHouse has SELECT modifiers that can help us: APPLY, EXCEPT AND REPLACE.

Let’s see some easy examples using this simple set:

The first one APPLY will apply a function to all the columns we specify in the SELECT clause like:

Now, with EXCEPT we can select different columns except the ones specified, and we can combine the modifiers:

The last one is REPLACE that you can use again apply simple visual functions and replace columns with new values, using alias expressions:

Sweet right? well as we said you can mix them all like this:

or this,

And stay tuned for the next ClickHouse release 21.10 in which we can use a lambda function inside an APPLY.

Do you like this post?

Related posts

More Data, More Apps: Improving data ingestion in Tinybird
Low-code analytics with James Devonport of UserLoop
Tinybird
Team
May 05, 2023
Modern data management with real-time Change Data Capture
You can now explore and analyze time series data in Tinybird
To the limits of SQL... and beyond
Export data from Tinybird to Amazon S3 with the S3 Sink
Tinybird
Team
Mar 21, 2024
8 example projects to master real-time data engineering
Killing the ProcessPoolExecutor
Tinybird
Team
Aug 09, 2023
The Data Journey: Unlocking data for the right now
Tinybird is SOC 2 Type II compliant
Tinybird
Team
Dec 19, 2022

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.
Need more? Contact sales for Enterprise support.