Seaquel
PostgreSQL error code

PostgreSQL error 22013

22013 is the SQLSTATE PostgreSQL reports for invalid preceding or following size, in class 22, Data Exception.

SQLSTATE22013
Condition nameinvalid_preceding_or_following_size
Class22 — Data Exception

Reproduce it, then fix it

A frame offset counts rows back or forward from the current one, so it can’t be negative. For a window over the previous row and this one, write 1 PRECEDING. Run the broken query to see the error, then switch to the fixed one. Edit either freely; every run is rolled back.

SELECT id, price,
  avg(price) OVER (ORDER BY id ROWS BETWEEN -1 PRECEDING AND CURRENT ROW) AS moving_avg
FROM products;
SELECT id, price,
  avg(price) OVER (ORDER BY id ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) AS moving_avg
FROM products;

Source: PostgreSQL documentation, Appendix A