File: test_window_exclude.test_slow

package info (click to toggle)
duckdb 1.5.1-3
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 299,196 kB
  • sloc: cpp: 865,414; ansic: 57,292; python: 18,871; sql: 12,663; lisp: 11,751; yacc: 7,412; lex: 1,682; sh: 747; makefile: 564
file content (885 lines) | stat: -rw-r--r-- 16,002 bytes parent folder | download | duplicates (3)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
# name: test/sql/window/test_window_exclude.test_slow
# description: Windows with EXCLUDE clause
# group: [window]

statement ok
PRAGMA enable_verification

statement ok
CREATE TABLE tenk1d (
        unique1	        int4,
		four		int4,
        col             int4
);

statement ok
INSERT INTO tenk1d (unique1, four, col) VALUES 
  (0, 0, NULL),
  (1, 1, 1),
  (2, 2, NULL),
  (3, 3, 3),
  (4, 0, NULL),
  (5, 1, 1),
  (6, 2, NULL),
  (7, 3, 3),
  (8, 0, NULL),
  (9, 1, 1);

statement ok
CREATE TABLE empsalary (
depname varchar,
empno bigint,
salary int,
enroll_date date
);

statement ok
INSERT INTO empsalary VALUES
('develop', 10, 5200, '2007-08-01'),
('sales', 1, 5000, '2006-10-01'),
('personnel', 5, 3500, '2007-12-10'),
('sales', 4, 4800, '2007-08-08'),
('personnel', 2, 3900, '2006-12-23'),
('develop', 7, 4200, '2008-01-01'),
('develop', 9, 4500, '2008-01-01'),
('sales', 3, 4800, '2007-08-01'),
('develop', 8, 6000, '2006-10-01'),
('develop', 11, 5200, '2007-08-15');

# RANGE + CURRENT ROW
query III
SELECT sum(unique1) over (w range between unbounded preceding and current row exclude current row),
	unique1, four
FROM tenk1d  WINDOW w AS (order by four) ORDER BY four, unique1;
----
12	0	0
8	4	0
4	8	0
26	1	1
22	5	1
18	9	1
33	2	2
29	6	2
42	3	3
38	7	3

# RANGE + GROUP
query III
SELECT sum(unique1) over (w range between unbounded preceding and current row exclude group),
	unique1, four
FROM tenk1d  WINDOW w AS (order by four) ORDER BY four, unique1;
----
NULL	0	0
NULL	4	0
NULL	8	0
12	1	1
12	5	1
12	9	1
27	2	2
27	6	2
35	3	3
35	7	3

# RANGE + TIES
query III
SELECT sum(unique1) over (w range between unbounded preceding and current row exclude ties),
	unique1, four
FROM tenk1d  WINDOW w AS (order by four) ORDER BY four, unique1;
----
0	0	0
4	4	0
8	8	0
13	1	1
17	5	1
21	9	1
29	2	2
33	6	2
38	3	3
42	7	3

# with PARTITION BY
query III
SELECT sum(unique1) over (partition by four order by unique1 range between 5::int8 preceding and 6::int2 following
	exclude current row),unique1, four
FROM tenk1d  ORDER BY four, unique1;
----
4	0	0
8	4	0
4	8	0
5	1	1
10	5	1
5	9	1
6	2	2
2	6	2
7	3	3
3	7	3

# with FILTER
query III
SELECT sum(unique1) filter (where four > 1)over (order by unique1 rows between unbounded preceding and current row
	exclude current row),unique1, four
FROM tenk1d  ORDER BY unique1, four;
----
NULL	0	0
NULL	1	1
NULL	2	2
2	3	3
5	4	0
5	5	1
5	6	2
11	7	3
18	8	0
18	9	1

# with FILTER and PARTITION BY
query III
SELECT sum(unique1) filter (where four > 0) over (partition by four order by unique1 rows between unbounded preceding
        and current row exclude current row),unique1, four
FROM tenk1d  ORDER BY unique1, four;
----
NULL	0	0
NULL	1	1
NULL	2	2
NULL	3	3
NULL	4	0
1	5	1
2	6	2
3	7	3
NULL	8	0
6	9	1

# first_value
query II
SELECT first_value(four) over (order by four rows between unbounded preceding
        and current row exclude group), four
FROM tenk1d ORDER BY four;
----
NULL	0
NULL	0
NULL	0
0	1
0	1
0	1
0	2
0	2
0	3
0	3


# last_value
query II
SELECT last_value(four) over (order by four rows between current row
        and unbounded following exclude current row), four
FROM tenk1d ORDER BY four;
----
3	0
3	0
3	0
3	1
3	1
3	1
3	2
3	2
3	3
NULL	3


# nth_value
query II
SELECT nth_value(four, 5) over (order by four rows between unbounded preceding
        and unbounded following exclude ties), four
FROM tenk1d ORDER BY four;
----
2	0
2	0
2	0
2	1
2	1
2	1
1	2
1	2
1	3
1	3



# IGNORE NULLS
query III
SELECT nth_value(col, 3 ignore nulls) over (order by four rows between unbounded preceding                                               
       and unbounded following exclude current row),four, col
FROM tenk1d ORDER BY four, col;
----
1	0	NULL
1	0	NULL
1	0	NULL
3	1	1
3	1	1
3	1	1
1	2	NULL
1	2	NULL
1	3	3
1	3	3 


# IGNORE NULLS with input > STANDARD_VECTOR_SIZE
query I
SELECT DISTINCT first_value(col IGNORE NULLS) OVER (ORDER BY i ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING EXCLUDE CURRENT ROW)
FROM (  SELECT * 
        FROM generate_series(1,3000) AS _(i), (SELECT NULL::integer)
          UNION ALL
        SELECT 3001, 1
     ) AS _(i, col)
ORDER BY ALL NULLS FIRST;
----
NULL
1


# without ORDER BY: EXCLUDE CURRENT ROW / constant aggregate otherwise
query II
SELECT sum(unique1) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING EXCLUDE CURRENT ROW), unique1
FROM tenk1d ORDER BY unique1;
----
45	0
44	1
43	2
42	3
41	4
40	5
39	6
38	7
37	8
36	9


# without ORDER BY: EXCLUDE GROUP / constant aggregate otherwise
query II
SELECT sum(unique1) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING EXCLUDE GROUP), unique1
FROM tenk1d ORDER BY unique1;
----
NULL	0
NULL	1
NULL	2
NULL	3
NULL	4
NULL	5
NULL	6
NULL	7
NULL	8
NULL	9


# without ORDER BY: EXCLUDE TIES / constant aggregate otherwise
query II
SELECT sum(unique1) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING EXCLUDE TIES), unique1
FROM tenk1d ORDER BY unique1;
----
0	0
1	1
2	2
3	3
4	4
5	5
6	6
7	7
8	8
9	9

# input larger than standard vector size (with EXCLUDE GROUP and vector-crossing peer boundary)
query II
SELECT DISTINCT j,sum(j) OVER (ORDER BY j ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING EXCLUDE GROUP) FROM generate_series(1,300), generate_series(1,10) AS __(j) ORDER BY j;
----
1	16200
2	15900
3	15600
4	15300
5	15000
6	14700
7	14400
8	14100
9	13800
10	13500


# with WHERE clause
query II
SELECT i, last_value(i) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING EXCLUDE CURRENT ROW) FROM generate_series(1,10) AS _(i)
WHERE i <> 10
ORDER BY i;
----
1	9
2	9
3	9
4	9
5	9
6	9
7	9
8	9
9	8


# regression test
query II
SELECT DISTINCT j,sum(j) OVER (ORDER BY j ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING EXCLUDE TIES) FROM generate_series(1,300), generate_series(1,10) AS __(j) ORDER BY j;
----
1	16201
2	15902
3	15603
4	15304
5	15005
6	14706
7	14407
8	14108
9	13809
10	13510

# regression test
query II
SELECT DISTINCT j,sum(j) FILTER (where i <> 3) OVER (ORDER BY j ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING EXCLUDE TIES) AS sum FROM generate_series(1,300) _(i), generate_series(1,10) AS __(j) ORDER BY j, sum;
----
1	16146
1	16147
2	15847
2	15849
3	15548
3	15551
4	15249
4	15253
5	14950
5	14955
6	14651
6	14657
7	14352
7	14359
8	14053
8	14061
9	13754
9	13763
10	13455
10	13465

# regression test
query II
SELECT j, sum(j) OVER (ORDER BY j ROWS BETWEEN UNBOUNDED PRECEDING AND 30 FOLLOWING EXCLUDE CURRENT ROW) FROM generate_series(1,40) AS _(j) ORDER BY j;
----
1	495
2	526
3	558
4	591
5	625
6	660
7	696
8	733
9	771
10	810
11	809
12	808
13	807
14	806
15	805
16	804
17	803
18	802
19	801
20	800
21	799
22	798
23	797
24	796
25	795
26	794
27	793
28	792
29	791
30	790
31	789
32	788
33	787
34	786
35	785
36	784
37	783
38	782
39	781
40	780

# Query otherwise handled by STREAMING WINDOW
query TT
EXPLAIN
SELECT unique1, COUNT(*) OVER(ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW EXCLUDE CURRENT ROW) FROM tenk1d;
----
physical_plan	<!REGEX>:.*STREAMING_WINDOW.*



# PARTITION BY without ORDER BY
query III
SELECT unique1, four, sum(unique1) OVER (PARTITION BY four ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING EXCLUDE CURRENT ROW) FROM tenk1d ORDER BY four, unique1;
----
0 	0 	12
4 	0 	8
8 	0 	4
1 	1 	14
5 	1 	10
9 	1 	6
2 	2 	6
6 	2 	2
3 	3 	7
7 	3 	3

# PARTITION BY without ORDER BY
query III
SELECT unique1, four, sum(unique1) OVER (PARTITION BY four ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING EXCLUDE GROUP) FROM tenk1d ORDER BY four, unique1;
----
0 	0 	NULL
4 	0 	NULL
8 	0 	NULL
1 	1 	NULL
5 	1 	NULL
9 	1 	NULL
2 	2 	NULL
6 	2 	NULL
3 	3 	NULL
7 	3 	NULL


# PARTITION BY without ORDER BY
query III
SELECT unique1, four, sum(unique1) OVER (PARTITION BY four ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING EXCLUDE TIES) FROM tenk1d ORDER BY four, unique1;
----
0 	0 	0
4 	0 	4
8 	0 	8
1 	1 	1
5 	1 	5
9 	1 	9
2 	2 	2
6 	2 	6
3 	3 	3
7 	3 	7


#
# Custom aggregates (not implemented yet)
#

## COUNT(*) and CURRENT ROW
query II
SELECT i, COUNT(*) OVER (ORDER BY i ROWS BETWEEN 3 PRECEDING AND 3 FOLLOWING EXCLUDE CURRENT ROW) 
FROM generate_series(1,10) AS _(i) 
ORDER BY i;
----
1 	3
2 	4
3 	5
4 	6
5 	6
6 	6
7 	6
8 	5
9 	4
10 	3

## COUNT(*) and GROUP
query II
SELECT i, COUNT(*) OVER (ORDER BY i ROWS BETWEEN 3 PRECEDING AND 3 FOLLOWING EXCLUDE GROUP) 
FROM (
	SELECT * FROM generate_series(1,5) 
	UNION ALL 
	SELECT * FROM generate_series(1,5)
) AS _(i) 
ORDER BY i;
----
1 	2
1 	3
2 	4
2 	5
3 	5
3 	5
4 	5
4 	4
5 	3
5 	2


## COUNT(*) and TIES
query II
SELECT i, COUNT(*) OVER (ORDER BY i ROWS BETWEEN 3 PRECEDING AND 3 FOLLOWING EXCLUDE TIES) 
FROM (
	SELECT *  FROM generate_series(1,5) 
	UNION ALL 
	SELECT *  FROM generate_series(1,5)) 
	AS _(i) 
ORDER BY i;
----
1 	3
1 	4
2 	5
2 	6
3 	6
3 	6
4 	6
4 	5
5 	4
5 	3

## ARRAY_AGG and CURRENT ROW
query II
SELECT i, array_agg(i) OVER w AS aai
FROM (
	SELECT * FROM generate_series(1,5)
    UNION ALL
    SELECT * FROM generate_series(1,5) 
) AS _(i)
WINDOW w AS (ORDER BY i ROWS UNBOUNDED PRECEDING EXCLUDE CURRENT ROW)
ORDER BY i, aai NULLS FIRST;
----
1	NULL
1	[1]
2	[1, 1]
2	[1, 1, 2]
3	[1, 1, 2, 2]
3	[1, 1, 2, 2, 3]
4	[1, 1, 2, 2, 3, 3]
4	[1, 1, 2, 2, 3, 3, 4]
5	[1, 1, 2, 2, 3, 3, 4, 4]
5	[1, 1, 2, 2, 3, 3, 4, 4, 5]

## ARRAY_AGG and GROUP
query II
SELECT i, array_agg(i) OVER w
FROM (
	SELECT * FROM generate_series(1,5)
    UNION ALL
    SELECT * FROM generate_series(1,5) 
) AS _(i)
WINDOW w AS (ORDER BY i ROWS UNBOUNDED PRECEDING EXCLUDE GROUP)
ORDER BY i;
----
1	NULL
1	NULL
2	[1, 1]
2	[1, 1]
3	[1, 1, 2, 2]
3	[1, 1, 2, 2]
4	[1, 1, 2, 2, 3, 3]
4	[1, 1, 2, 2, 3, 3]
5	[1, 1, 2, 2, 3, 3, 4, 4]
5	[1, 1, 2, 2, 3, 3, 4, 4]

## ARRAY_AGG and TIES
query II
SELECT i, array_agg(i) OVER w
FROM (
	SELECT * FROM generate_series(1,5)
    UNION ALL
    SELECT * FROM generate_series(1,5) 
) AS _(i)
WINDOW w AS (ORDER BY i ROWS UNBOUNDED PRECEDING EXCLUDE TIES)
ORDER BY i;
----
1	[1]
1	[1]
2	[1, 1, 2]
2	[1, 1, 2]
3	[1, 1, 2, 2, 3]
3	[1, 1, 2, 2, 3]
4	[1, 1, 2, 2, 3, 3, 4]
4	[1, 1, 2, 2, 3, 3, 4]
5	[1, 1, 2, 2, 3, 3, 4, 4, 5]
5	[1, 1, 2, 2, 3, 3, 4, 4, 5]

# MODE and CURRENT ROW
query II
SELECT i, mode(i) OVER  w
FROM (
	SELECT i FROM generate_series(1,3) t(i), range(4)
) AS _(i)
WINDOW w AS (ORDER BY i ROWS BETWEEN 1 PRECEDING AND 2 FOLLOWING EXCLUDE CURRENT ROW)
ORDER BY ALL;
----
1	1
1	1
1	1
1	2
2	2
2	2
2	2
2	3
3	3
3	3
3	3
3	3

# MODE and GROUP
query II
SELECT i, mode(i) OVER  w
FROM (
	SELECT i FROM generate_series(1,3) t(i), range(4)
) AS _(i)
WINDOW w AS (ORDER BY i ROWS BETWEEN 1 PRECEDING AND 2 FOLLOWING EXCLUDE GROUP)
ORDER BY ALL;
----
1	2
1	2
1	NULL
1	NULL
2	1
2	3
2	3
2	NULL
3	2
3	NULL
3	NULL
3	NULL

# MODE and TIES
query II
SELECT i, mode(i) OVER w
FROM (
	FROM repeat(1, 10)
	UNION ALL
	FROM repeat(2, 4)
	UNION ALL
	FROM repeat(3, 5)
) AS _(i)
WINDOW w AS (ORDER BY i ROWS BETWEEN CURRENT ROW AND 100 FOLLOWING EXCLUDE TIES)
ORDER BY ALL;
----
1	3
1	3
1	3
1	3
1	3
1	3
1	3
1	3
1	3
1	3
2	3
2	3
2	3
2	3
3	3
3	3
3	3
3	3
3	3

# MEDIAN and CURRENT ROW
query II
SELECT i, median(i) OVER (ORDER BY i ROWS BETWEEN 1 PRECEDING AND 2 FOLLOWING EXCLUDE CURRENT ROW) 
FROM generate_series(1,10) AS _(i) ORDER BY i;
----
1	2.5
2	3.0
3	4.0
4	5.0
5	6.0
6	7.0
7	8.0
8	9.0
9	9.0
10	9.0

# MEDIAN and GROUP
query II
SELECT i, median(i) OVER (ORDER BY i ROWS BETWEEN 1 PRECEDING AND 2 FOLLOWING EXCLUDE GROUP) 
FROM generate_series(1,5) AS _(i), 
	generate_series(1,2) 
ORDER BY i;
----
1	2.0
1	2.0
2	2.0
2	3.0
3	3.0
3	4.0
4	4.0
4	5.0
5	4.0
5	NULL

# MEDIAN and TIES
query II
SELECT i, median(i) OVER (ORDER BY i ROWS BETWEEN 1 PRECEDING AND 2 FOLLOWING EXCLUDE TIES) 
FROM generate_series(1,5) AS _(i), 
	generate_series(1,2) 
ORDER BY i;
----
1	1.5
1	2.0
2	2.0
2	3.0
3	3.0
3	4.0
4	4.0
4	5.0
5	4.5
5	5.0

# Test Merge Sort Trees with exclusions
query III
WITH t1(x, y) AS (VALUES
 ( 1, 3 ),
 ( 2, 2 ),
 ( 3, 1 )
)
SELECT x, y, QUANTILE_DISC(y, 0) OVER (
	ORDER BY x 
	ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
	EXCLUDE CURRENT ROW)
FROM t1;
----
1	3	NULL
2	2	3
3	1	2

query III
WITH t1(x, y) AS (VALUES
 ( 1, 3 ),
 ( 2, 2 ),
 ( 3, 1 )
)
SELECT x, y, QUANTILE_DISC(y, 0) OVER (
	ORDER BY x 
	ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
	EXCLUDE CURRENT ROW)
FROM t1;
----
1	3	1
2	2	1
3	1	2


# PG test
query III
select sum(salary) over (order by enroll_date range between '1 year'::interval preceding and '1 year'::interval following
	exclude current row), salary, enroll_date from empsalary ORDER BY enroll_date, salary;
----
29900	5000	2006-10-01
28900	6000	2006-10-01
34500	3900	2006-12-23
42300	4800	2007-08-01
41900	5200	2007-08-01
42300	4800	2007-08-08
41900	5200	2007-08-15
32600	3500	2007-12-10
28000	4200	2008-01-01
27700	4500	2008-01-01

# PG test
query III
select sum(salary) over (order by enroll_date range between '1 year'::interval preceding and '1 year'::interval following
	exclude group), salary, enroll_date from empsalary ORDER BY enroll_date, salary;
----
23900	5000	2006-10-01
23900	6000	2006-10-01
34500	3900	2006-12-23
37100	4800	2007-08-01
37100	5200	2007-08-01
42300	4800	2007-08-08
41900	5200	2007-08-15
32600	3500	2007-12-10
23500	4200	2008-01-01
23500	4500	2008-01-01

# PG test
query III
select sum(salary) over (order by enroll_date range between '1 year'::interval preceding and '1 year'::interval following
	exclude ties), salary, enroll_date from empsalary ORDER BY enroll_date, salary;
----
28900	5000	2006-10-01
29900	6000	2006-10-01
38400	3900	2006-12-23
41900	4800	2007-08-01
42300	5200	2007-08-01
47100	4800	2007-08-08
47100	5200	2007-08-15
36100	3500	2007-12-10
27700	4200	2008-01-01
28000	4500	2008-01-01

# PG test
query IIII
select first_value(salary) over(order by salary range between 1000 preceding and 1000 following) AS first_value,
	lead(salary) over(order by salary range between 1000 preceding and 1000 following) AS lead,
	nth_value(salary, 1) over(order by salary range between 1000 preceding and 1000 following),
	salary from empsalary ORDER BY first_value, lead;
----
3500	3900	3500	3500
3500	4200	3500	3900
3500	4500	3500	4200
3500	4800	3500	4500
3900	4800	3900	4800
3900	5000	3900	4800
4200	5200	4200	5000
4200	5200	4200	5200
4200	6000	4200	5200
5000	NULL	5000	6000

# PG test
query III
select last_value(salary) over(order by salary range between 1000 preceding and 1000 following) AS last_value,
	lag(salary) over(order by salary range between 1000 preceding and 1000 following) AS lag,
	salary from empsalary ORDER BY last_value, lag;
----
4500	NULL	3500
4800	3500	3900
5200	3900	4200
5200	4200	4500
5200	4500	4800
5200	4800	4800
6000	4800	5000
6000	5000	5200
6000	5200	5200
6000	5200	6000

# PG test
query IIII
select first_value(salary) over(order by salary range between 1000 following and 3000 following
	exclude current row) AS first_value,
	lead(salary) over(order by salary range between 1000 following and 3000 following exclude ties) AS lead,
	nth_value(salary, 1) over(order by salary range between 1000 following and 3000 following
	exclude ties),
	salary from empsalary ORDER BY first_value, lead;
----
4500	3900	4500	3500
5000	4200	5000	3900
5200	4500	5200	4200
6000	4800	6000	4500
6000	4800	6000	4800
6000	5000	6000	4800
6000	5200	6000	5000
NULL	5200	NULL	5200
NULL	6000	NULL	5200
NULL	NULL	NULL	6000

# PG test
query III
select last_value(salary) over(order by salary range between 1000 following and 3000 following
	exclude group) AS last_value,
	lag(salary) over(order by salary range between 1000 following and 3000 following exclude group) AS lag,
	salary from empsalary ORDER BY last_value, lag;
----
6000	3500	3900
6000	3900	4200
6000	4200	4500
6000	4500	4800
6000	4800	4800
6000	4800	5000
6000	NULL	3500
NULL	5000	5200
NULL	5200	5200
NULL	5200	6000


statement error
SELECT sum(i) OVER (EXCLUDE CURRENT ROW) FROM generate_series(1,10) AS _(i);
----
Parser Error: syntax error at or near "CURRENT"

statement error
SELECT sum(i) OVER (ROWS UNBOUNDED PRECEDING EXCLUDE GROUPS) FROM generate_series(1,10) AS _(i);
----
Parser Error: syntax error at or near "GROUPS"