Hi Henson,
> Before I send the fixes, I would like to agree on one design point:
> whether, and how, planning keeps the argument of a navigation such as
> PREV() from raising an error at plan time. Section 2 asks you to
> choose between two options. The fix changes how this is implemented,
> so I want to explain the change, and the other ways I tried, before
> you see the patch.
>
> The problem:
>
> WITH t(id, v) AS (VALUES (1, 10))
> SELECT count(*) OVER w AS cnt
> FROM t
> WINDOW w AS (ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
> PATTERN (A) DEFINE A AS PREV(v / 0) > 0);
>
> A navigation evaluates its argument only at the row it moves to, and
> not at all when there is no such row. Here the only row has no
> previous row, so the query should return 0. But pull-up replaces v
> with 10, and constant folding then raises division by zero at plan
> time.
With v55 I don't see the error?
test=#\i test.sql
WITH t(id, v) AS (VALUES (1, 10))
SELECT count(*) OVER w AS cnt
FROM t
WINDOW w AS (ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
PATTERN (A) DEFINE A AS PREV(v / 0) > 0);
cnt
-----
0
(1 row)
Regards,
--
Tatsuo Ishii
SRA OSS K.K.
English: http://www.sraoss.co.jp/index_en/
Japanese:http://www.sraoss.co.jp