On this page
Kater SQL Functions Derive
KATER__MAP
A label for each value you list, and one label for every other value.
Family: Derive
Syntax
KATER__MAP(field, (value, label) [, ...] [, default_label => 'label'])Arguments
Required
| Argument | Description |
|---|---|
field | The field whose values get labels. |
mappings | Each value and the label it gets. One or more (value, 'label') pairs. |
Optional
| Argument | Description |
|---|---|
default_label | The label for each value you do not list, and for an empty value. A value, or a parameter a reader supplies. It is 'Other' when left out. |
Returns
Text.
Usage notes
- A value matches by equality, so
(NULL, 'label')never matches. An empty value getsdefault_label.
Example
This Sandbox query reads the sample shop’s orders. The table shows the rows that Kater gave.
SELECT orders.channel AS "Channel", KATER__MAP(orders.channel, ('paid', 'Paid media'), ('email', 'Owned'), ('web', 'Owned'), default_label => 'Offline') AS "Channel Group"FROM kater_dataset.orders AS ordersGROUP BY orders.channel, KATER__MAP(orders.channel, ('paid', 'Paid media'), ('email', 'Owned'), ('web', 'Owned'), default_label => 'Offline')ORDER BY 1| Channel | Channel Group |
|---|---|
| Owned | |
| paid | Paid media |
| store | Offline |
| web | Owned |
Compiles to
The call compiles to the same SQL on DuckDB and on Snowflake.
CASE WHEN orders.channel = 'paid' THEN 'Paid media' WHEN orders.channel = 'email' THEN 'Owned' WHEN orders.channel = 'web' THEN 'Owned' ELSE 'Offline'ENDSee also
- Groups and flags
- Other functions in Derive:
KATER__BUCKET,KATER__PERIODS_SINCE