Coco Expressions
Construct new columns based on existing data using a subset of SQL.
Overview
Section titled “Overview”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.
Expressions
Section titled “Expressions”Since Coco Expressions don’t allow full statements, this means statements like
SELECT Salary + 2 AS my_new_column FROM my_frameare not allowed.
Instead, you would only provided the expression component, in a new column.
Salary + 2Using Functions
Section titled “Using Functions”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).
Using Aggregates
Section titled “Using Aggregates”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") + AgeThe expression above will calculate the average for the entire Age column, and take that scalar result and apply it to each cell for Age.
Conditionals via CASE WHEN
Section titled “Conditionals via CASE WHEN”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 CountryENDAliases Are Not Allowed
Section titled “Aliases Are Not Allowed”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 domainLive Updates
Section titled “Live Updates”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.