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 #***********************************************************************
11 # This file implements regression tests for SQLite library.
14 set testdir [file dirname $argv0]
15 source $testdir/tester.tcl
16 set testprefix window9
18 ifcapable !windowfunc {
25 name TEXT COLLATE NOCASE,
26 color TEXT COLLATE NOCASE
31 INSERT INTO fruits (name, color) VALUES ('apple', 'RED');
32 INSERT INTO fruits (name, color) VALUES ('APPLE', 'yellow');
33 INSERT INTO fruits (name, color) VALUES ('pear', 'YELLOW');
34 INSERT INTO fruits (name, color) VALUES ('PEAR', 'green');
38 SELECT name, color, dense_rank() OVER (ORDER BY name) FROM fruits;
48 dense_rank() OVER (PARTITION BY name ORDER BY color)
59 dense_rank() OVER (ORDER BY name),
60 dense_rank() OVER (PARTITION BY name ORDER BY color)
71 dense_rank() OVER (ORDER BY name),
72 dense_rank() OVER (PARTITION BY name ORDER BY color)
73 FROM fruits ORDER BY color;
82 CREATE TABLE t1(a BLOB, b INTEGER, c COLLATE nocase);
83 INSERT INTO t1 VALUES(1, 2, 'abc');
84 INSERT INTO t1 VALUES(3, 4, 'ABC');
87 do_execsql_test 2.1.1 {
88 SELECT c=='Abc' FROM t1
90 do_execsql_test 2.1.2 {
91 SELECT c=='Abc', rank() OVER (ORDER BY b) FROM t1
94 do_execsql_test 2.2.1 {
97 do_execsql_test 2.2.2 {
98 SELECT b=='2', rank() OVER (ORDER BY a) FROM t1
101 #-------------------------------------------------------------------------
103 do_execsql_test 3.0 {
105 CREATE TABLE t2(a,b,c);
108 do_execsql_test 3.1 {
109 SELECT EXISTS(SELECT 1 FROM t1 ORDER BY sum(a) OVER ()) FROM t1;
112 do_execsql_test 3.2 {
113 SELECT sum(a) OVER () FROM t2
114 ORDER BY EXISTS(SELECT 1 FROM t2 ORDER BY sum(a) OVER ());
117 do_catchsql_test 3.3 {
118 SELECT a, sum(a) OVER (ORDER BY a DESC) FROM t2
120 SELECT 1 FROM t2 ORDER BY sum(a) OVER (ORDER BY a)
122 } {1 {near "OVER": syntax error}}
124 do_catchsql_test 3.4 {
125 SELECT y, y+1, y+2 FROM (
127 SELECT min(a) OVER (),
128 (abs(row_number() OVER())+22)/19,
129 max(a) OVER () FROM t1
132 } {1 {sub-select returns 3 columns - expected 1}}
134 #-------------------------------------------------------------------------
136 do_execsql_test 4.0 {
137 CREATE TABLE t1(a, b TEXT);
138 INSERT INTO t1 VALUES('A', 1), ('A', 2), ('2', 1), ('2', 2);
141 do_execsql_test 4.1.1 {
142 SELECT b, b=count(*), '1,2' FROM t1 GROUP BY b;
144 do_execsql_test 4.1.2 {
145 SELECT b, b=count(*), group_concat(b) OVER () FROM t1 GROUP BY b;
148 #--------------------------------------------------------------------------
150 do_execsql_test 5.0 {
151 CREATE TABLE t1(a, b, c, d, e);
152 CREATE INDEX i1 ON t1(a, b, c, d, e);
159 sum(e) OVER (ORDER BY a),
160 sum(e) OVER (PARTITION BY a ORDER BY b),
161 sum(e) OVER (PARTITION BY a, b ORDER BY c),
162 sum(e) OVER (PARTITION BY a, b, c ORDER BY d)
166 SELECT sum(e) OVER (PARTITION BY a ORDER BY b) FROM t1 ORDER BY a;
170 execsql "EXPLAIN QUERY PLAN $sql"
174 #-------------------------------------------------------------------------
176 do_execsql_test 6.0 {
178 INSERT INTO t0(c0) VALUES (0);
181 do_execsql_test 6.1 {
182 SELECT * FROM t0 WHERE
184 SELECT MIN(c0) OVER (), CUME_DIST() OVER () FROM t0
187 SELECT MIN(c0) OVER (), CUME_DIST() OVER () FROM t0
191 do_execsql_test 6.2 {
192 SELECT * FROM t0 WHERE EXISTS (
193 SELECT MIN(c0) OVER (), CUME_DIST() OVER () FROM t0
198 #-------------------------------------------------------------------------
200 do_execsql_test 7.0 {
201 DROP TABLE IF EXISTS t1;
202 CREATE TABLE t1(x, y);
203 INSERT INTO t1 VALUES(10, 1);
204 INSERT INTO t1 VALUES(20, 2);
205 INSERT INTO t1 VALUES(3, 3);
206 INSERT INTO t1 VALUES(2, 4);
207 INSERT INTO t1 VALUES(1, 5);
211 do_execsql_test 7.1 {
212 SELECT avg(x) OVER (ORDER BY y) AS z FROM t1 ORDER BY z
214 7.2 8.75 10.0 11.0 15.0
217 do_execsql_test 7.2 {
218 SELECT avg(x) OVER (ORDER BY y) z FROM t1 ORDER BY (z IS y);
220 10.0 15.0 11.0 8.75 7.2
223 do_execsql_test 7.3 {
224 SELECT avg(x) OVER (ORDER BY y) z FROM t1 ORDER BY (y IS z);
226 10.0 15.0 11.0 8.75 7.2
229 do_execsql_test 7.4 {
230 SELECT avg(x) OVER (ORDER BY y) z FROM t1 ORDER BY z + 0.0;
232 7.2 8.75 10.0 11.0 15.0
235 #-------------------------------------------------------------------------
237 do_execsql_test 8.1.1 {
238 CREATE TABLE t1(a, b);
239 INSERT INTO t1 VALUES(1, 2), (3, 4);
240 SELECT min( sum(a) ) OVER () FROM t1;
243 do_execsql_test 8.1.2 {
244 SELECT min( sum(a) ) OVER () FROM t1 GROUP BY a;
247 do_execsql_test 8.2 {
251 SELECT count() OVER() FROM (SELECT 0)
256 do_catchsql_test 8.3 {
257 SELECT min( max((SELECT x FROM v1)) ) OVER()
260 do_execsql_test 8.4 {
263 SELECT sum( avg((SELECT x FROM v1)) ) OVER()
268 #--------------------------------------------------------------------------
270 do_execsql_test 9.0 {
271 CREATE TABLE t1(a, b, c);
272 INSERT INTO t1 VALUES(NULL,'bb',356);
273 INSERT INTO t1 VALUES('CB','aa',158);
274 INSERT INTO t1 VALUES('BB','aa',399);
275 INSERT INTO t1 VALUES('FF','bb',938);
278 do_catchsql_test 9.1 {
280 ORDER BY c RANGE BETWEEN 0 PRECEDING AND '-700' PRECEDING
283 } {1 {frame ending offset must be a non-negative number}}