aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/permutations.test2
-rw-r--r--test/window1.test112
2 files changed, 113 insertions, 1 deletions
diff --git a/test/permutations.test b/test/permutations.test
index 52e2509fc..d240b34da 100644
--- a/test/permutations.test
+++ b/test/permutations.test
@@ -167,7 +167,7 @@ test_suite "veryquick" -prefix "" -description {
that test malloc and IO errors are omitted.
} -files [
test_set $allquicktests -exclude *malloc* *ioerr* *fault* *bigfile* *_err* \
- *fts5corrupt* *fts5big* *fts5aj*
+ *fts5corrupt* *fts5big* *fts5aj* *expert* table.test
]
test_suite "extraquick" -prefix "" -description {
diff --git a/test/window1.test b/test/window1.test
new file mode 100644
index 000000000..70961f8c6
--- /dev/null
+++ b/test/window1.test
@@ -0,0 +1,112 @@
+# 2018 May 8
+#
+# The author disclaims copyright to this source code. In place of
+# a legal notice, here is a blessing:
+#
+# May you do good and not evil.
+# May you find forgiveness for yourself and forgive others.
+# May you share freely, never taking more than you give.
+#
+#***********************************************************************
+# This file implements regression tests for SQLite library.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set testprefix window1
+
+
+do_execsql_test 1.0 {
+ CREATE TABLE t1(a, b, c, d);
+ INSERT INTO t1 VALUES(1, 2, 3, 4);
+ INSERT INTO t1 VALUES(5, 6, 7, 8);
+ INSERT INTO t1 VALUES(9, 10, 11, 12);
+}
+
+do_execsql_test 1.1 {
+ SELECT sum(b) OVER () FROM t1
+} {18 18 18}
+
+do_execsql_test 1.2 {
+ SELECT a, sum(b) OVER () FROM t1
+} {1 18 5 18 9 18}
+
+do_execsql_test 1.3 {
+ SELECT a, 4 + sum(b) OVER () FROM t1
+} {1 22 5 22 9 22}
+
+do_execsql_test 1.4 {
+ SELECT a + 4 + sum(b) OVER () FROM t1
+} {23 27 31}
+
+do_execsql_test 1.5 {
+ SELECT a, sum(b) OVER (PARTITION BY c) FROM t1
+} {1 2 5 6 9 10}
+
+foreach {tn sql} {
+ 1 "SELECT sum(b) OVER () FROM t1"
+ 2 "SELECT sum(b) OVER (PARTITION BY c) FROM t1"
+ 3 "SELECT sum(b) OVER (ORDER BY c) FROM t1"
+ 4 "SELECT sum(b) OVER (PARTITION BY d ORDER BY c) FROM t1"
+ 5 "SELECT sum(b) FILTER (WHERE a>0) OVER (PARTITION BY d ORDER BY c) FROM t1"
+ 6 "SELECT sum(b) OVER (ORDER BY c RANGE UNBOUNDED PRECEDING) FROM t1"
+ 7 "SELECT sum(b) OVER (ORDER BY c ROWS 45 PRECEDING) FROM t1"
+ 8 "SELECT sum(b) OVER (ORDER BY c RANGE CURRENT ROW) FROM t1"
+ 9 "SELECT sum(b) OVER (ORDER BY c RANGE BETWEEN UNBOUNDED PRECEDING
+ AND CURRENT ROW) FROM t1"
+ 10 "SELECT sum(b) OVER (ORDER BY c ROWS BETWEEN UNBOUNDED PRECEDING
+ AND UNBOUNDED FOLLOWING) FROM t1"
+} {
+ do_test 2.$tn { lindex [catchsql $sql] 0 } 0
+}
+
+foreach {tn sql} {
+ 1 "SELECT * FROM t1 WHERE sum(b) OVER ()"
+ 2 "SELECT * FROM t1 GROUP BY sum(b) OVER ()"
+ 3 "SELECT * FROM t1 GROUP BY a HAVING sum(b) OVER ()"
+} {
+ do_catchsql_test 3.$tn $sql {1 {misuse of window function sum()}}
+}
+
+do_execsql_test 4.0 {
+ CREATE TABLE t2(a, b, c);
+ INSERT INTO t2 VALUES(0, 0, 0);
+ INSERT INTO t2 VALUES(1, 1, 1);
+ INSERT INTO t2 VALUES(2, 0, 2);
+ INSERT INTO t2 VALUES(3, 1, 0);
+ INSERT INTO t2 VALUES(4, 0, 1);
+ INSERT INTO t2 VALUES(5, 1, 2);
+ INSERT INTO t2 VALUES(6, 0, 0);
+}
+
+do_execsql_test 4.1 {
+ SELECT a, sum(a) OVER (PARTITION BY b) FROM t2;
+} {
+ 0 12 2 12 4 12 6 12 1 9 3 9 5 9
+}
+
+do_execsql_test 4.2 {
+ SELECT a, sum(a) OVER (PARTITION BY b) FROM t2 ORDER BY a;
+} {
+ 0 12 1 9 2 12 3 9 4 12 5 9 6 12
+}
+
+do_execsql_test 4.3 {
+ SELECT a, sum(a) OVER () FROM t2 ORDER BY a;
+} {
+ 0 21 1 21 2 21 3 21 4 21 5 21 6 21
+}
+
+do_execsql_test 4.4 {
+ SELECT a, sum(a) OVER (ORDER BY a) FROM t2;
+} {
+ 0 0 1 1 2 3 3 6 4 10 5 15 6 21
+}
+
+do_execsql_test 4.5 {
+ SELECT a, sum(a) OVER (PARTITION BY b ORDER BY a) FROM t2 ORDER BY a
+} {
+ 0 0 1 1 2 2 3 4 4 6 5 9 6 12
+}
+
+finish_test