Applying function chaining
In this section, we’ll introduce function chaining, an elegant programming style for calling multiple scalar functions sequentially. Function chaining (sometimes termed method chaining) is a familiar technique in object-orientated programming languages – and DuckDB supports this elegant style to increase the readability of code. This will be familiar to users of Python. So, let’s learn how to use function chaining in DuckDB SQL.
We will be using our skiers
table from the previous section. Let’s familiarize ourselves with the data available by querying the two name columns:
SELECT skier_first_name, skier_last_name FROM skiers;
This returns the string fields shown in the following screenshot:
Figure 10.7 – The name fields of the skiers table
Let’s say we want to format the names of our skiers by performing the following steps:
- Concatenate
skier_first_name
andskier_last_name...