Postgresql Named Windows

The documentation for the Postgresql Window Function seems to imply that you can use the same window in several places in your query. However, I cannot figure out how to create a named window?

SELECT first_value(vin) OVER( PARTITION BY vin ) AS w, first_value(make) OVER w
FROM inventory.vehicles
WHERE lot_Id = 9999 AND make is not null;

This is a comic request in which I try to get the syntax.

ERROR: window "w" does not exist

+3
source share
1 answer

The answer was actually in the SELECTdoc:

WINDOW Item

WINDOW's optional offer has a general view

WINDOW window_name AS (window_definition) [, ...]

SELECT first_value(vin) OVER w
, first_value(make) OVER w
FROM inventory.vehicles
WHERE lot_Id = 9999 AND make is not null
WINDOW w AS ( PARTITION by vin );
+6
source

Source: https://habr.com/ru/post/1759034/