Window function
Returns a non-NULL bucket number for each row. Invalid or NULL bucket counts raise an error.
Syntax
A window function keeps each input row and adds a result for that row. PARTITION BY groups rows with matching values; without it, all input rows form one group.
Window
- NTILE assigns buckets using all ordered rows in each group. A ROWS frame clause does not change the buckets. RANGE frames with numeric or time offsets are not supported.
Arguments
Returns
- Type: BIGINT
- Possible values: 1 through min(buckets, number of rows in the group).
- NULL behavior: Returns a non-NULL bucket number for each row. Invalid or NULL bucket counts raise an error.
- Empty input: An empty input produces no rows.
Properties
Usage notes
- When rows do not divide evenly, the earliest buckets get one extra row.
- When there are more buckets than rows, only one bucket number per row is emitted.
- An explicit frame does not change NTILE’s bucket assignment. All rows in the PARTITION BY group are used.
Examples
Uneven bucket sizes
More buckets than rows
Last modified on October 15, 2026