Skip to main content
Skip to main content

first_value

It is an alias for any but it was introduced for compatibility with Window Functions, where sometimes it's necessary to process NULL values (by default all ClickHouse aggregate functions ignore NULL values).

It supports declaring a modifier to respect nulls (RESPECT NULLS), both under Window Functions and in normal aggregations.

As with any, without Window Functions the result will be random if the source stream is not ordered and the return type matches the input type (Null is only returned if the input is Nullable or -OrNull combinator is added).

examples

example1

By default, the NULL value is ignored.

example2

The NULL value is ignored.

example3

The NULL value is accepted.

example4

Stabilized result using the sub-query with ORDER BY.