Skip to main content
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

ArgumentDescription
fieldThe field whose values get labels.
mappingsEach value and the label it gets. One or more (value, 'label') pairs.

Optional

ArgumentDescription
default_labelThe 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 gets default_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 orders
GROUP BY
orders.channel,
KATER__MAP(orders.channel, ('paid', 'Paid media'), ('email', 'Owned'), ('web', 'Owned'), default_label => 'Offline')
ORDER BY
1
ChannelChannel Group
emailOwned
paidPaid media
storeOffline
webOwned

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'
END

See also