1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
PRAGMA WindowNewPipeline;
$data = [
<|a: NULL, b: 1, count1: 5, count2: 5|>,
<|a: NULL, b: 1, count1: 5, count2: 5|>,
<|a: pgint2('1000'), b: 1, count1: 3, count2: 3|>,
<|a: pgint2('2000'), b: 1, count1: 2, count2: 3|>,
<|a: pgint2('3000'), b: 1, count1: 1, count2: 3|>,
<|a: pgint2('1'), b: 2, count1: 2, count2: 2|>,
<|a: pgint2('2'), b: 2, count1: 2, count2: 2|>,
];
$win_result = (
SELECT
COUNT(*) OVER w1 AS actual_count,
COUNT(*) OVER w2 AS actual_count2,
count1,
count2,
FROM
AS_TABLE($data)
WINDOW
w1 AS (
PARTITION COMPACT BY
b
ORDER BY
a DESC
RANGE BETWEEN UNBOUNDED PRECEDING AND pgnumeric('1') FOLLOWING
),
w2 AS (
PARTITION COMPACT BY
b
ORDER BY
a DESC
RANGE BETWEEN UNBOUNDED PRECEDING AND pgfloat8('10000000000') FOLLOWING
)
);
SELECT
Ensure(actual_count, count1 IS NOT DISTINCT FROM actual_count),
Ensure(actual_count2, count2 IS NOT DISTINCT FROM actual_count2),
FROM
$win_result
;
|