Skip to content
REFERENCE

Coco Expressions

Construct new columns based on existing data using a subset of SQL.

Coco Expressions provide a way to quickly create new columns in Coco Alemana.

The syntax is based on CocoSQL, but involves only a singular expression. This expression can be thought of the expression that you use to create a new column in SQL.

Since Coco Expressions don’t allow full statements, this means statements like

SELECT Salary + 2 AS my_new_column FROM my_frame

are not allowed.

Instead, you would only provided the expression component, in a new column.

Salary + 2

You can use functions as part of the expressions too. This follows the same rule, of a singular expression.

Take the example below

split(trim("Email"), '@')[2]

Which would split email by the @ symbol, and take the second half (domain).

Aggregates are allowed in expressions, but they work slightly differently. Since expressions don’t provided a grouping, the aggregate will apply over the entire referenced column.

AVERAGE("Age") + Age

The expression above will calculate the average for the entire Age column, and take that scalar result and apply it to each cell for Age.

You’re able to use CASE WHEN statements to conditionally modify values. This is similar to an IF statement in other languages.

CASE
WHEN "Country" = 'Spain' THEN 'España'
ELSE Country
END

Aliases are not allowed in Coco Expressions. To rename the result, you can just rename the outcome column.

This means this expression is invalid.

split(trim("Email"), '@')[2] AS domain

Live updates will occur as you type, no matter the size of the data. This gives you a fantastic way to check your equation before applying your changes.