3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give.
10 #***********************************************************************
13 source [file join [file dirname
$argv0] pg_common.tcl
]
15 #=========================================================================
18 start_test window2
"2018 May 19"
23 DROP TABLE IF EXISTS t1
;
24 CREATE TABLE t1
(a INTEGER PRIMARY KEY
, b TEXT
, c TEXT
, d INTEGER
);
25 INSERT INTO t1 VALUES
(1, 'odd'
, 'one'
, 1);
26 INSERT INTO t1 VALUES
(2, 'even'
, 'two'
, 2);
27 INSERT INTO t1 VALUES
(3, 'odd'
, 'three'
, 3);
28 INSERT INTO t1 VALUES
(4, 'even'
, 'four'
, 4);
29 INSERT INTO t1 VALUES
(5, 'odd'
, 'five'
, 5);
30 INSERT INTO t1 VALUES
(6, 'even'
, 'six'
, 6);
34 SELECT c
, sum
(d
) OVER
(PARTITION BY b ORDER BY c
) FROM t1
;
38 SELECT sum
(d
) OVER
() FROM t1
;
42 SELECT sum
(d
) OVER
(PARTITION BY b
) FROM t1
;
47 SELECT a
, sum
(d
) OVER
(
49 ROWS BETWEEN
1000 PRECEDING AND
1 FOLLOWING
53 SELECT a
, sum
(d
) OVER
(
55 ROWS BETWEEN
1000 PRECEDING AND
1000 FOLLOWING
59 SELECT a
, sum
(d
) OVER
(
61 ROWS BETWEEN
1 PRECEDING AND
1000 FOLLOWING
65 SELECT a
, sum
(d
) OVER
(
67 ROWS BETWEEN
1 PRECEDING AND
1 FOLLOWING
71 SELECT a
, sum
(d
) OVER
(
73 ROWS BETWEEN
1 PRECEDING AND
0 FOLLOWING
78 SELECT a
, sum
(d
) OVER
(
81 ROWS BETWEEN
1 PRECEDING AND
1 FOLLOWING
86 SELECT a
, sum
(d
) OVER
(
89 ROWS BETWEEN
0 PRECEDING AND
0 FOLLOWING
94 SELECT a
, sum
(d
) OVER
(
96 ROWS BETWEEN CURRENT ROW AND
2 FOLLOWING
101 SELECT a
, sum
(d
) OVER
(
103 ROWS BETWEEN UNBOUNDED PRECEDING AND
2 FOLLOWING
108 SELECT a
, sum
(d
) OVER
(
110 ROWS BETWEEN CURRENT ROW AND
2 FOLLOWING
115 SELECT a
, sum
(d
) OVER
(
117 ROWS BETWEEN
2 PRECEDING AND CURRENT ROW
122 SELECT a
, sum
(d
) OVER
(
124 ROWS BETWEEN
2 PRECEDING AND UNBOUNDED FOLLOWING
129 SELECT a
, sum
(d
) OVER
(
131 ROWS BETWEEN
3 PRECEDING AND
1 PRECEDING
136 SELECT a
, sum
(d
) OVER
(
139 ROWS BETWEEN
1 PRECEDING AND
0 PRECEDING
144 SELECT a
, sum
(d
) OVER
(
147 ROWS BETWEEN
1 PRECEDING AND
1 PRECEDING
152 SELECT a
, sum
(d
) OVER
(
155 ROWS BETWEEN
1 PRECEDING AND
2 PRECEDING
160 SELECT a
, sum
(d
) OVER
(
163 ROWS BETWEEN UNBOUNDED PRECEDING AND
2 PRECEDING
168 SELECT a
, sum
(d
) OVER
(
171 ROWS BETWEEN
1 FOLLOWING AND
3 FOLLOWING
176 SELECT a
, sum
(d
) OVER
(
178 ROWS BETWEEN
1 FOLLOWING AND
2 FOLLOWING
183 SELECT a
, sum
(d
) OVER
(
185 ROWS BETWEEN
1 FOLLOWING AND UNBOUNDED FOLLOWING
190 SELECT a
, sum
(d
) OVER
(
193 ROWS BETWEEN
1 FOLLOWING AND UNBOUNDED FOLLOWING
198 SELECT a
, sum
(d
) OVER
(
200 ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
205 SELECT a
, sum
(d
) OVER
(
208 ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
213 SELECT a
, sum
(d
) OVER
(
215 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
220 SELECT a
, sum
(d
) OVER
(
223 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
228 SELECT a
, sum
(d
) OVER
(
230 ROWS BETWEEN CURRENT ROW AND CURRENT ROW
235 SELECT a
, sum
(d
) OVER
(
238 ROWS BETWEEN CURRENT ROW AND CURRENT ROW
243 SELECT a
, sum
(d
) OVER
(
245 RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
249 SELECT a
, sum
(d
) OVER
(
251 RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
256 SELECT a
, sum
(d
) OVER
(
257 PARTITION BY b ORDER BY d
258 RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
263 SELECT a
, sum
(d
) OVER
(
265 RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
270 SELECT a
, sum
(d
) OVER
(
272 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
277 SELECT a
, sum
(d
) OVER
(
279 ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
283 #puts $::fd finish_test
288 DROP TABLE IF EXISTS t2
;
289 CREATE TABLE t2
(a INTEGER PRIMARY KEY
, b INTEGER
);
290 INSERT INTO t2
(a
, b
) VALUES
291 (1,0), (2,74), (3,41), (4,74), (5,23), (6,99), (7,26), (8,33), (9,2),
292 (10,89), (11,81), (12,96), (13,59), (14,38), (15,68), (16,39), (17,62),
293 (18,91), (19,46), (20,6), (21,99), (22,97), (23,27), (24,46), (25,78),
294 (26,54), (27,97), (28,8), (29,67), (30,29), (31,93), (32,84), (33,77),
295 (34,23), (35,16), (36,16), (37,93), (38,65), (39,35), (40,47), (41,7),
296 (42,86), (43,74), (44,61), (45,91), (46,85), (47,24), (48,85), (49,43),
297 (50,59), (51,12), (52,32), (53,56), (54,3), (55,91), (56,22), (57,90),
298 (58,55), (59,15), (60,28), (61,89), (62,25), (63,47), (64,1), (65,56),
299 (66,40), (67,43), (68,56), (69,16), (70,75), (71,36), (72,89), (73,98),
300 (74,76), (75,81), (76,4), (77,94), (78,42), (79,30), (80,78), (81,33),
301 (82,29), (83,53), (84,63), (85,2), (86,87), (87,37), (88,80), (89,84),
302 (90,72), (91,41), (92,9), (93,61), (94,73), (95,95), (96,65), (97,13),
303 (98,58), (99,96), (100,98), (101,1), (102,21), (103,74), (104,65), (105,35),
304 (106,5), (107,73), (108,11), (109,51), (110,87), (111,41), (112,12), (113,8),
305 (114,20), (115,31), (116,31), (117,15), (118,95), (119,22), (120,73),
306 (121,79), (122,88), (123,34), (124,8), (125,11), (126,49), (127,34),
307 (128,90), (129,59), (130,96), (131,60), (132,55), (133,75), (134,77),
308 (135,44), (136,2), (137,7), (138,85), (139,57), (140,74), (141,29), (142,70),
309 (143,59), (144,19), (145,39), (146,26), (147,26), (148,47), (149,80),
310 (150,90), (151,36), (152,58), (153,47), (154,9), (155,72), (156,72), (157,66),
311 (158,33), (159,93), (160,75), (161,64), (162,81), (163,9), (164,23), (165,37),
312 (166,13), (167,12), (168,14), (169,62), (170,91), (171,36), (172,91),
313 (173,33), (174,15), (175,34), (176,36), (177,99), (178,3), (179,95), (180,69),
314 (181,58), (182,52), (183,30), (184,50), (185,84), (186,10), (187,84),
315 (188,33), (189,21), (190,39), (191,44), (192,58), (193,30), (194,38),
316 (195,34), (196,83), (197,27), (198,82), (199,17), (200,7);
320 SELECT a
, sum
(b
) OVER
(
323 ) FROM t2 ORDER BY a
;
327 SELECT a
, sum
(b
) OVER
(
330 RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
331 ) FROM t2 ORDER BY a
;
335 SELECT b
, sum
(b
) OVER
(
337 ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
338 ) FROM t2 ORDER BY b
;
342 SELECT b
, sum
(b
) OVER
(
344 RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
345 ) FROM t2 ORDER BY b
;
349 SELECT b
, sum
(b
) OVER
(
351 RANGE BETWEEN CURRENT ROW AND CURRENT ROW
352 ) FROM t2 ORDER BY b
;
356 SELECT b
, sum
(b
) OVER
(
357 RANGE BETWEEN CURRENT ROW AND CURRENT ROW
358 ) FROM t2 ORDER BY b
;
361 SELECT b
, sum
(b
) OVER
() FROM t2 ORDER BY b
;
364 SELECT b
, sum
(b
) OVER
(
365 RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
366 ) FROM t2 ORDER BY b
;
369 SELECT b
, sum
(b
) OVER
(
370 RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
371 ) FROM t2 ORDER BY b
;
375 SELECT b
, sum
(b
) OVER
(
376 ROWS BETWEEN CURRENT ROW AND CURRENT ROW
377 ) FROM t2 ORDER BY
1, 2;
380 SELECT b
, sum
(b
) OVER
(
381 ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
382 ) FROM t2 ORDER BY
1, 2;
385 SELECT b
, sum
(b
) OVER
(
386 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
387 ) FROM t2 ORDER BY
1, 2;
390 SELECT b
, sum
(b
) OVER
(
391 ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
392 ) FROM t2 ORDER BY
1, 2;
396 SELECT b
, sum
(b
) OVER
(
398 ROWS BETWEEN CURRENT ROW AND CURRENT ROW
399 ) FROM t2 ORDER BY
1, 2;
402 SELECT b
, sum
(b
) OVER
(
404 ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
405 ) FROM t2 ORDER BY
1, 2;
408 SELECT b
, sum
(b
) OVER
(
410 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
411 ) FROM t2 ORDER BY
1, 2;
414 SELECT b
, sum
(b
) OVER
(
416 ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
417 ) FROM t2 ORDER BY
1, 2;