Creating Top-K Projections

You define a Top-K projection with the following syntax:

CREATE PROJECTION proj-name [(proj-column-spec)]
	AS SELECT select-expression FROM table
	LIMIT num-rows OVER (PARTITION BY expression ORDER BY column-expr);

For full syntax options, see CREATE PROJECTION (Live Aggregate Projections).

For example:

=> CREATE PROJECTION readings_topk (meter_id, recent_date, recent_value)
	AS SELECT meter_id, reading_date, reading_value FROM readings
	LIMIT 5 OVER (PARTITION BY meter_id ORDER BY reading_date DESC);

For an extended discussion, see Top-K Projection Examples.

Requirements

The following requirements apply to Top-K projections:

Restrictions

The following restrictions apply to Top-K projections: