Seaquel
PostgreSQL error code

PostgreSQL error 42P20

42P20 is the SQLSTATE PostgreSQL reports for windowing error, in class 42, Syntax Error or Access Rule Violation.

SQLSTATE42P20
Condition namewindowing_error
Class42 — Syntax Error or Access Rule Violation

Reproduce it, then fix it

These are the queries from the guide below. Run the broken query to see the error, then switch to the fixed one. Edit either freely; every run is rolled back.

SELECT name, category, price
FROM demo.products
WHERE RANK() OVER (PARTITION BY category ORDER BY price DESC) = 1;
SELECT name, category, price
FROM (
  SELECT
    name, category, price,
    RANK() OVER (PARTITION BY category ORDER BY price DESC) AS price_rank
  FROM demo.products
) ranked
WHERE price_rank = 1;

How to fix it

In other databases

Source: PostgreSQL documentation, Appendix A