table_window
Window functions over partitions and orders.
Flags
| Flag | Value |
|---|---|
| Kind | construct: makes a value from values |
| Rows | keeps the rows |
| Deterministic | yes |
| Order matters | no |
| Decomposable | no |
| Makes | a table value |
Parameters
| Parameter | Type | Required | Notes |
|---|---|---|---|
table |
reference | yes | A value's reference. |
partition_by |
array of expr | no | The partitions. |
order_by |
array of sort_key | no | The order within a partition; ordered functions need it. |
columns |
array of named | no | The appended columns: window functions or aggregates. |
frame |
frame | no | The rows an aggregate sees: unit rows or range (peers as one), start and end bounds. Default: the partition start to the current row's last peer with an order_by, the whole partition without. Ranking and lag/lead ignore it. |
response_format |
"concise" | "detailed" | no | The byte budget: 64 KiB concise, 512 KiB detailed. |
Example
Over the example tables orders; ${input:name} is an input's reference and ${verb} the value an earlier call made.
table_window {
"table": "${input:orders}",
"partition_by": [
{
"col": 1
}
],
"order_by": [
{
"expr": {
"col": 2
},
"descending": true
}
],
"columns": [
{
"name": "rank",
"expr": {
"fn": "row_number",
"args": []
}
}
]
}Result
240 rows
{
"ref": "sha256:75d190e160fe22cc6f2e4ed18347b553f2ec070b0cf5d115ff8824977c2c3d73",
"kind": "table",
"rows": 240,
"schema": "…"
}In the hint language
The same step as a plan, as the language prints it.
output out = from orders
window {rank = row_number()} by:{customer} order:{amount desc}Diagnostics
A refusal comes back as ok: false with coded diagnostics; every code, with its fix, is on the diagnostics page. A parameter that does not match the schema above is ARG_INVALID, with the parameter's path.