Skip to content

RFC: Fractional LIMIT #81892

@alexey-milovidov

Description

@alexey-milovidov

Company or project name

ClickHouse

Use case

Taking records from the middle of the resultset of unknown size, to simplify some analytic scenarios.

Describe the solution you'd like

Fractional values in the 0..1 interval will represent quantiles of the resultset instead of fixed numbers of elements.

Example:

SELECT * FROM table ORDER BY x LIMIT 0.1; -- returns first 10% of the result
SELECT * FROM table ORDER BY x LIMIT 0.5, 0.25; -- returns 3rd quartile of the result
SELECT * FROM table ORDER BY x LIMIT 0.5, 1; -- returns a single record, which is the median of the result

Describe alternatives you've considered

Instead of using fractions, we can introduce a % syntax specifically for LIMIT. But it would be less composable with constant expressions and aliases.

Additional context

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions