PostgreSQL error code
PostgreSQL error 42P20
42P20 is the SQLSTATE PostgreSQL reports for windowing error, in class 42, Syntax Error or Access Rule Violation.
| SQLSTATE | 42P20 |
|---|---|
| Condition name | windowing_error |
| Class | 42 — 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;