WINDOW Clause (Named Window)
WINDOW Clause (Named Window) is a SQL clause in the PostgreSQL Specific category. PostgreSQL: defines a named window that can be referenced by multiple window functions, avoiding repetition. The syntax is SELECT ... WINDOW w AS (PARTITION BY col ORDER BY col);. It returns named window result. A typical example: SELECT name, dept, salary, ROW_NUMBER() OVER w AS row_num, RANK() OVER w AS rank, DENSE_RANK() OVER w AS dense_rank FROM employees WINDOW w AS (PARTITION BY dept ORDER BY salary DESC); -- Same window definition reused for 3 window functions A close relative is SERIAL, which postgreSQL auto-increment type. Creates an INTEGER column with a sequence. Equivalent to AUTO_INCREMENT in MySQL. A close relative is RETURNING, which postgreSQL extension that returns values from INSERT/UPDATE/DELETE statements (like OUTPUT in SQL Server). A close relative is ARRAY, which postgreSQL supports array columns and array operations. Can be multi-dimensional.