1ac662732Sdrh# 2019-08-30 2ac662732Sdrh# 3ac662732Sdrh# The author disclaims copyright to this source code. In place of 4ac662732Sdrh# a legal notice, here is a blessing: 5ac662732Sdrh# 6ac662732Sdrh# May you do good and not evil. 7ac662732Sdrh# May you find forgiveness for yourself and forgive others. 8ac662732Sdrh# May you share freely, never taking more than you give. 9ac662732Sdrh# 10ac662732Sdrh#*********************************************************************** 11ac662732Sdrh# Test cases for RANGE BETWEEN and especially with NULLS LAST 12ac662732Sdrh# 13ac662732Sdrh 14ac662732Sdrhset testdir [file dirname $argv0] 15ac662732Sdrhsource $testdir/tester.tcl 16ac662732Sdrhset testprefix windowA 17ac662732Sdrh 18ac662732Sdrhifcapable !windowfunc { 19ac662732Sdrh finish_test 20ac662732Sdrh return 21ac662732Sdrh} 22ac662732Sdrh 23ac662732Sdrhdo_execsql_test 1.0 { 24ac662732Sdrh CREATE TABLE t1(a INTEGER PRIMARY KEY, b CHAR(1), d FLOAT); 25ac662732Sdrh INSERT INTO t1 VALUES 26ac662732Sdrh (1, 'A', 5.4), 27ac662732Sdrh (2, 'B', 5.55), 28ac662732Sdrh (3, 'C', 8.0), 29ac662732Sdrh (4, 'D', 10.25), 30ac662732Sdrh (5, 'E', 10.26), 31ac662732Sdrh (6, 'N', NULL), 32ac662732Sdrh (7, 'N', NULL); 33ac662732Sdrh} {} 34ac662732Sdrh 35ac662732Sdrhdo_execsql_test 1.1 { 36ac662732Sdrh SELECT a, b, quote(d), group_concat(b,'') OVER w1 FROM t1 37ac662732Sdrh WINDOW w1 AS 38ac662732Sdrh (ORDER BY d DESC NULLS LAST 39ac662732Sdrh RANGE BETWEEN 2.50 PRECEDING AND 2.25 FOLLOWING) 40ac662732Sdrh ORDER BY +d DESC NULLS LAST, +a; 41ac662732Sdrh} [list \ 42ac662732Sdrh 5 E 10.26 ED \ 43ac662732Sdrh 4 D 10.25 EDC \ 44ac662732Sdrh 3 C 8.0 EDC \ 45ac662732Sdrh 2 B 5.55 CBA \ 46ac662732Sdrh 1 A 5.4 BA \ 47ac662732Sdrh 6 N NULL NN \ 48ac662732Sdrh 7 N NULL NN \ 49ac662732Sdrh] 50ac662732Sdrh 51ac662732Sdrhdo_execsql_test 1.2 { 52ac662732Sdrh SELECT a, b, quote(d), group_concat(b,'') OVER w1 FROM t1 53ac662732Sdrh WINDOW w1 AS 54ac662732Sdrh (ORDER BY d DESC NULLS FIRST 55ac662732Sdrh RANGE BETWEEN 2.50 PRECEDING AND 2.25 FOLLOWING) 56ac662732Sdrh ORDER BY +d DESC NULLS FIRST, +a; 57ac662732Sdrh} [list \ 58ac662732Sdrh 6 N NULL NN \ 59ac662732Sdrh 7 N NULL NN \ 60ac662732Sdrh 5 E 10.26 ED \ 61ac662732Sdrh 4 D 10.25 EDC \ 62ac662732Sdrh 3 C 8.0 EDC \ 63ac662732Sdrh 2 B 5.55 CBA \ 64ac662732Sdrh 1 A 5.4 BA \ 65ac662732Sdrh] 66ac662732Sdrh 67ac662732Sdrhdo_execsql_test 1.3 { 68ac662732Sdrh SELECT a, b, quote(d), group_concat(b,'') OVER w1 FROM t1 69ac662732Sdrh WINDOW w1 AS 70ac662732Sdrh (ORDER BY d DESC NULLS LAST 71ac662732Sdrh RANGE BETWEEN 2.50 PRECEDING AND UNBOUNDED FOLLOWING) 72ac662732Sdrh ORDER BY +d DESC NULLS LAST, +a; 73ac662732Sdrh} [list \ 74ac662732Sdrh 5 E 10.26 EDCBANN \ 75ac662732Sdrh 4 D 10.25 EDCBANN \ 76ac662732Sdrh 3 C 8.0 EDCBANN \ 77ac662732Sdrh 2 B 5.55 CBANN \ 78ac662732Sdrh 1 A 5.4 BANN \ 79ac662732Sdrh 6 N NULL NN \ 80ac662732Sdrh 7 N NULL NN \ 81ac662732Sdrh] 82ac662732Sdrh 83ac662732Sdrhdo_execsql_test 1.4 { 84ac662732Sdrh SELECT a, b, quote(d), group_concat(b,'') OVER w1 FROM t1 85ac662732Sdrh WINDOW w1 AS 86ac662732Sdrh (ORDER BY d DESC NULLS FIRST 87ac662732Sdrh RANGE BETWEEN 2.50 PRECEDING AND UNBOUNDED FOLLOWING) 88ac662732Sdrh ORDER BY +d DESC NULLS FIRST, +a; 89ac662732Sdrh} [list \ 90ac662732Sdrh 6 N NULL NNEDCBA \ 91ac662732Sdrh 7 N NULL NNEDCBA \ 92ac662732Sdrh 5 E 10.26 EDCBA \ 93ac662732Sdrh 4 D 10.25 EDCBA \ 94ac662732Sdrh 3 C 8.0 EDCBA \ 95ac662732Sdrh 2 B 5.55 CBA \ 96ac662732Sdrh 1 A 5.4 BA \ 97ac662732Sdrh] 98ac662732Sdrh 99ac662732Sdrhdo_execsql_test 1.5 { 100ac662732Sdrh SELECT a, b, quote(d), group_concat(b,'') OVER w1 FROM t1 101ac662732Sdrh WINDOW w1 AS 102ac662732Sdrh (ORDER BY d DESC NULLS LAST 103ac662732Sdrh RANGE BETWEEN 2.50 PRECEDING AND CURRENT ROW) 104ac662732Sdrh ORDER BY +d DESC NULLS LAST, +a; 105ac662732Sdrh} [list \ 106ac662732Sdrh 5 E 10.26 E \ 107ac662732Sdrh 4 D 10.25 ED \ 108ac662732Sdrh 3 C 8.0 EDC \ 109ac662732Sdrh 2 B 5.55 CB \ 110ac662732Sdrh 1 A 5.4 BA \ 111ac662732Sdrh 6 N NULL NN \ 112ac662732Sdrh 7 N NULL NN \ 113ac662732Sdrh] 114ac662732Sdrh 115ac662732Sdrhdo_execsql_test 1.6 { 116ac662732Sdrh SELECT a, b, quote(d), group_concat(b,'') OVER w1 FROM t1 117ac662732Sdrh WINDOW w1 AS 118ac662732Sdrh (ORDER BY d DESC NULLS FIRST 119ac662732Sdrh RANGE BETWEEN 2.50 PRECEDING AND CURRENT ROW) 120ac662732Sdrh ORDER BY +d DESC NULLS FIRST, +a; 121ac662732Sdrh} [list \ 122ac662732Sdrh 6 N NULL NN \ 123ac662732Sdrh 7 N NULL NN \ 124ac662732Sdrh 5 E 10.26 E \ 125ac662732Sdrh 4 D 10.25 ED \ 126ac662732Sdrh 3 C 8.0 EDC \ 127ac662732Sdrh 2 B 5.55 CB \ 128ac662732Sdrh 1 A 5.4 BA \ 129ac662732Sdrh] 130ac662732Sdrh 131ac662732Sdrhdo_execsql_test 2.1 { 132ac662732Sdrh SELECT a, b, quote(d), group_concat(b,'') OVER w1 FROM t1 133ac662732Sdrh WINDOW w1 AS 134ac662732Sdrh (ORDER BY d DESC NULLS LAST 135ac662732Sdrh RANGE BETWEEN UNBOUNDED PRECEDING AND 2.25 FOLLOWING) 136ac662732Sdrh ORDER BY +d DESC NULLS LAST, +a; 137ac662732Sdrh} [list \ 138ac662732Sdrh 5 E 10.26 ED \ 139ac662732Sdrh 4 D 10.25 EDC \ 140ac662732Sdrh 3 C 8.0 EDC \ 141ac662732Sdrh 2 B 5.55 EDCBA \ 142ac662732Sdrh 1 A 5.4 EDCBA \ 143ac662732Sdrh 6 N NULL EDCBANN \ 144ac662732Sdrh 7 N NULL EDCBANN \ 145ac662732Sdrh] 146ac662732Sdrh 147ac662732Sdrhdo_execsql_test 2.2 { 148ac662732Sdrh SELECT a, b, quote(d), group_concat(b,'') OVER w1 FROM t1 149ac662732Sdrh WINDOW w1 AS 150ac662732Sdrh (ORDER BY d DESC NULLS FIRST 151ac662732Sdrh RANGE BETWEEN UNBOUNDED PRECEDING AND 2.25 FOLLOWING) 152ac662732Sdrh ORDER BY +d DESC NULLS FIRST, +a; 153ac662732Sdrh} [list \ 154ac662732Sdrh 6 N NULL NN \ 155ac662732Sdrh 7 N NULL NN \ 156ac662732Sdrh 5 E 10.26 NNED \ 157ac662732Sdrh 4 D 10.25 NNEDC \ 158ac662732Sdrh 3 C 8.0 NNEDC \ 159ac662732Sdrh 2 B 5.55 NNEDCBA \ 160ac662732Sdrh 1 A 5.4 NNEDCBA \ 161ac662732Sdrh] 162ac662732Sdrh 163ac662732Sdrhdo_execsql_test 2.3 { 164ac662732Sdrh SELECT a, b, quote(d), group_concat(b,'') OVER w1 FROM t1 165ac662732Sdrh WINDOW w1 AS 166ac662732Sdrh (ORDER BY d DESC NULLS LAST 167ac662732Sdrh RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) 168ac662732Sdrh ORDER BY +d DESC NULLS LAST, +a; 169ac662732Sdrh} [list \ 170ac662732Sdrh 5 E 10.26 EDCBANN \ 171ac662732Sdrh 4 D 10.25 EDCBANN \ 172ac662732Sdrh 3 C 8.0 EDCBANN \ 173ac662732Sdrh 2 B 5.55 EDCBANN \ 174ac662732Sdrh 1 A 5.4 EDCBANN \ 175ac662732Sdrh 6 N NULL EDCBANN \ 176ac662732Sdrh 7 N NULL EDCBANN \ 177ac662732Sdrh] 178ac662732Sdrh 179ac662732Sdrhdo_execsql_test 2.4 { 180ac662732Sdrh SELECT a, b, quote(d), group_concat(b,'') OVER w1 FROM t1 181ac662732Sdrh WINDOW w1 AS 182ac662732Sdrh (ORDER BY d DESC NULLS FIRST 183ac662732Sdrh RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) 184ac662732Sdrh ORDER BY +d DESC NULLS FIRST, +a; 185ac662732Sdrh} [list \ 186ac662732Sdrh 6 N NULL NNEDCBA \ 187ac662732Sdrh 7 N NULL NNEDCBA \ 188ac662732Sdrh 5 E 10.26 NNEDCBA \ 189ac662732Sdrh 4 D 10.25 NNEDCBA \ 190ac662732Sdrh 3 C 8.0 NNEDCBA \ 191ac662732Sdrh 2 B 5.55 NNEDCBA \ 192ac662732Sdrh 1 A 5.4 NNEDCBA \ 193ac662732Sdrh] 194ac662732Sdrh 195ac662732Sdrhdo_execsql_test 2.5 { 196ac662732Sdrh SELECT a, b, quote(d), group_concat(b,'') OVER w1 FROM t1 197ac662732Sdrh WINDOW w1 AS 198ac662732Sdrh (ORDER BY d DESC NULLS LAST 199ac662732Sdrh RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) 200ac662732Sdrh ORDER BY +d DESC NULLS LAST, +a; 201ac662732Sdrh} [list \ 202ac662732Sdrh 5 E 10.26 E \ 203ac662732Sdrh 4 D 10.25 ED \ 204ac662732Sdrh 3 C 8.0 EDC \ 205ac662732Sdrh 2 B 5.55 EDCB \ 206ac662732Sdrh 1 A 5.4 EDCBA \ 207ac662732Sdrh 6 N NULL EDCBANN \ 208ac662732Sdrh 7 N NULL EDCBANN \ 209ac662732Sdrh] 210ac662732Sdrh 211ac662732Sdrhdo_execsql_test 2.6 { 212ac662732Sdrh SELECT a, b, quote(d), group_concat(b,'') OVER w1 FROM t1 213ac662732Sdrh WINDOW w1 AS 214ac662732Sdrh (ORDER BY d DESC NULLS FIRST 215ac662732Sdrh RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) 216ac662732Sdrh ORDER BY +d DESC NULLS FIRST, +a; 217ac662732Sdrh} [list \ 218ac662732Sdrh 6 N NULL NN \ 219ac662732Sdrh 7 N NULL NN \ 220ac662732Sdrh 5 E 10.26 NNE \ 221ac662732Sdrh 4 D 10.25 NNED \ 222ac662732Sdrh 3 C 8.0 NNEDC \ 223ac662732Sdrh 2 B 5.55 NNEDCB \ 224ac662732Sdrh 1 A 5.4 NNEDCBA \ 225ac662732Sdrh] 226ac662732Sdrh 227ac662732Sdrh 228ac662732Sdrhdo_execsql_test 3.1 { 229ac662732Sdrh SELECT a, b, quote(d), group_concat(b,'') OVER w1 FROM t1 230ac662732Sdrh WINDOW w1 AS 231ac662732Sdrh (ORDER BY d DESC NULLS LAST 232ac662732Sdrh RANGE BETWEEN CURRENT ROW AND 2.25 FOLLOWING) 233ac662732Sdrh ORDER BY +d DESC NULLS LAST, +a; 234ac662732Sdrh} [list \ 235ac662732Sdrh 5 E 10.26 ED \ 236ac662732Sdrh 4 D 10.25 DC \ 237ac662732Sdrh 3 C 8.0 C \ 238ac662732Sdrh 2 B 5.55 BA \ 239ac662732Sdrh 1 A 5.4 A \ 240ac662732Sdrh 6 N NULL NN \ 241ac662732Sdrh 7 N NULL NN \ 242ac662732Sdrh] 243ac662732Sdrh 244ac662732Sdrhdo_execsql_test 3.2 { 245ac662732Sdrh SELECT a, b, quote(d), group_concat(b,'') OVER w1 FROM t1 246ac662732Sdrh WINDOW w1 AS 247ac662732Sdrh (ORDER BY d DESC NULLS FIRST 248ac662732Sdrh RANGE BETWEEN CURRENT ROW AND 2.25 FOLLOWING) 249ac662732Sdrh ORDER BY +d DESC NULLS FIRST, +a; 250ac662732Sdrh} [list \ 251ac662732Sdrh 6 N NULL NN \ 252ac662732Sdrh 7 N NULL NN \ 253ac662732Sdrh 5 E 10.26 ED \ 254ac662732Sdrh 4 D 10.25 DC \ 255ac662732Sdrh 3 C 8.0 C \ 256ac662732Sdrh 2 B 5.55 BA \ 257ac662732Sdrh 1 A 5.4 A \ 258ac662732Sdrh] 259ac662732Sdrh 260ac662732Sdrhdo_execsql_test 3.3 { 261ac662732Sdrh SELECT a, b, quote(d), group_concat(b,'') OVER w1 FROM t1 262ac662732Sdrh WINDOW w1 AS 263ac662732Sdrh (ORDER BY d DESC NULLS LAST 264ac662732Sdrh RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) 265ac662732Sdrh ORDER BY +d DESC NULLS LAST, +a; 266ac662732Sdrh} [list \ 267ac662732Sdrh 5 E 10.26 EDCBANN \ 268ac662732Sdrh 4 D 10.25 DCBANN \ 269ac662732Sdrh 3 C 8.0 CBANN \ 270ac662732Sdrh 2 B 5.55 BANN \ 271ac662732Sdrh 1 A 5.4 ANN \ 272ac662732Sdrh 6 N NULL NN \ 273ac662732Sdrh 7 N NULL NN \ 274ac662732Sdrh] 275ac662732Sdrh 276ac662732Sdrhdo_execsql_test 3.4 { 277ac662732Sdrh SELECT a, b, quote(d), group_concat(b,'') OVER w1 FROM t1 278ac662732Sdrh WINDOW w1 AS 279ac662732Sdrh (ORDER BY d DESC NULLS FIRST 280ac662732Sdrh RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) 281ac662732Sdrh ORDER BY +d DESC NULLS FIRST, +a; 282ac662732Sdrh} [list \ 283ac662732Sdrh 6 N NULL NNEDCBA \ 284ac662732Sdrh 7 N NULL NNEDCBA \ 285ac662732Sdrh 5 E 10.26 EDCBA \ 286ac662732Sdrh 4 D 10.25 DCBA \ 287ac662732Sdrh 3 C 8.0 CBA \ 288ac662732Sdrh 2 B 5.55 BA \ 289ac662732Sdrh 1 A 5.4 A \ 290ac662732Sdrh] 291ac662732Sdrh 292*db3a32edSdrhdo_execsql_test 4.0 { 293*db3a32edSdrh SELECT a, b, quote(d), group_concat(b,'') OVER w1 FROM t1 294*db3a32edSdrh WINDOW w1 AS 295*db3a32edSdrh (ORDER BY d DESC NULLS FIRST 296*db3a32edSdrh RANGE BETWEEN 2.50 PRECEDING AND 0.5 PRECEDING) 297*db3a32edSdrh ORDER BY +d DESC NULLS FIRST, +a; 298*db3a32edSdrh} [list \ 299*db3a32edSdrh 6 N NULL NN \ 300*db3a32edSdrh 7 N NULL NN \ 301*db3a32edSdrh 5 E 10.26 {} \ 302*db3a32edSdrh 4 D 10.25 {} \ 303*db3a32edSdrh 3 C 8.0 ED \ 304*db3a32edSdrh 2 B 5.55 C \ 305*db3a32edSdrh 1 A 5.4 {} \ 306*db3a32edSdrh] 307*db3a32edSdrh 308*db3a32edSdrh 309ac662732Sdrhfinish_test 310