table_topk
The k first rows by keys, with or without ties.
Flags
| Flag | Value |
|---|---|
| Kind | construct: makes a value from values |
| Rows | keeps some rows |
| Deterministic | yes |
| Order matters | no |
| Decomposable | yes |
| Makes | a table value |
Parameters
| Parameter | Type | Required | Notes |
|---|---|---|---|
table |
reference | yes | A value's reference. |
k |
integer | yes | at least 0. How many rows. |
keys |
array of sort_key | no | The order. |
with_ties |
boolean | no | Keep the rows tied with the k-th. |
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_topk {
"table": "${input:orders}",
"k": 5,
"keys": [
{
"expr": {
"col": 2
},
"descending": true
}
]
}Result
5 rows
{
"ref": "sha256:c2e2a4c1b7369c2f22541e3335405ec6172c45dc8d391b793229fb8d3fef22fd",
"kind": "table",
"rows": 5,
"schema": "…"
}In the hint language
The same step as a plan, as the language prints it.
output out = from orders
topk 5 {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.