select
AQL Syntax: Retrieves one or multiple fields
Definition
Run one expression or multiple expression over each row of a table and use the output to return a new table with the same number of row. In AQL, the select function serves as an intermediate step for subsequent transformations.
Syntax
select(table, expr1, expr2, ...)
select(table, col_name: expr1, ...)select(orders, orders.id, orders.status) // -> Table(orders.id, orders.status)
// with pipe
orders | select(orders.id, orders.status) | select(orders.id) // -> Table(orders.id)
// named column
orders | select(orders.status, formatted_status: concat('Status: ', orders.status))Input
table: A model reference or the returned table from a previous expression.expr(repeatable): An expression to evaluate for each row oftable.
You need to name the column in the output table (e.g. formatted_status: concat('Status: ', orders.status)). Only expression that has clear fully-qualified column name (e.g. orders.id) can be used directly and reference as-is in the output table.
Output
A table with the same number of rows as the input table, but with only the specified columns. E.g. select(orders, orders.id, formatted_status: concat('Status: ', orders.status) will return a table with 2 columns: orders.id and formatted_status.
| orders.status | formatted_status |
|---|---|
| pending | Status: pending |
| cancelled | Status: cancelled |
| pending | Status: pending |
Sample Usages
order_items | select(
countries.name,
products.name,
value: order_items.quantity * products.price
)| countries->name | products->name | value |
|---|---|---|
| Vietnam | Bunk Bed | 375 |
| Vietnam | Apple Watch 1 | 4880 |
| Vietnam | Lucky T-shirt | 387 |
| Vietnam | Shower curtains | 238 |
| Vietnam | Ticwatch 1 | 1128 |
| Vietnam | Nike Shoes | 700 |
| Vietnam | Xbox 360 | 1578 |
| Vietnam | Body Scrub | 390 |
| Vietnam | Nike Shoes | 358 |
| Vietnam | Chips 2. Dried Fruit | 26 |
| Vietnam | Dining Chair 2 | 344 |
order_items | select(value: order_items.quantity * products.price) | sum(value)| sum_value |
|---|
| 4391797 |