diff options
author | dan <dan@noemail.net> | 2020-06-09 17:45:48 +0000 |
---|---|---|
committer | dan <dan@noemail.net> | 2020-06-09 17:45:48 +0000 |
commit | ed41a96bc1e3a6eb011330b0a109ae4fc703a14c (patch) | |
tree | 42785e67f3f092e33289b83b2eb768c1af9784b0 /test | |
parent | cfb8bf6a501ccc5f67b9ae84ad1b6aa40bc1a374 (diff) | |
download | sqlite-ed41a96bc1e3a6eb011330b0a109ae4fc703a14c.tar.gz sqlite-ed41a96bc1e3a6eb011330b0a109ae4fc703a14c.zip |
Ensure that aggregate functions that (a) are part of SELECT statements with no FROM clause and (b) have one or more scalar sub-selects as arguments are assigned to the correct aggregate context.
FossilOrigin-Name: 16a41fa8c4c74bba4e908a9c19e6cf5a927cac140e2070c9abf303158be7257b
Diffstat (limited to 'test')
-rw-r--r-- | test/aggnested.test | 47 | ||||
-rw-r--r-- | test/window9.test | 4 |
2 files changed, 49 insertions, 2 deletions
diff --git a/test/aggnested.test b/test/aggnested.test index d712c840f..dcb1f95c9 100644 --- a/test/aggnested.test +++ b/test/aggnested.test @@ -17,6 +17,7 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl +set testprefix aggnested do_test aggnested-1.1 { db eval { @@ -259,6 +260,52 @@ do_execsql_test aggnested-4.4 { SELECT max((SELECT a FROM (SELECT count(*) AS a FROM ty) AS s)) FROM tx; } {3} +#-------------------------------------------------------------------------- +# +reset_db +do_execsql_test 5.0 { + CREATE TABLE x1(a, b); + INSERT INTO x1 VALUES(1, 2); + CREATE TABLE x2(x); + INSERT INTO x2 VALUES(NULL), (NULL), (NULL); +} + +# At one point, aggregate "total()" in the query below was being processed +# as part of the outer SELECT, not as part of the sub-select with no FROM +# clause. +do_execsql_test 5.1 { + SELECT ( SELECT total( (SELECT b FROM x1) ) ) FROM x2; +} {2.0 2.0 2.0} + +do_execsql_test 5.2 { + SELECT ( SELECT total( (SELECT 2 FROM x1) ) ) FROM x2; +} {2.0 2.0 2.0} + +do_execsql_test 5.3 { + CREATE TABLE t1(a); + CREATE TABLE t2(b); +} + +do_execsql_test 5.4 { + SELECT( + SELECT max(b) LIMIT ( + SELECT total( (SELECT a FROM t1) ) + ) + ) + FROM t2; +} {{}} + +do_execsql_test 5.5 { + CREATE TABLE a(b); + WITH c AS(SELECT a) + SELECT(SELECT(SELECT group_concat(b, b) + LIMIT(SELECT 0.100000 * + AVG(DISTINCT(SELECT 0 FROM a ORDER BY b, b, b)))) + FROM a GROUP BY b, + b, b) FROM a EXCEPT SELECT b FROM a ORDER BY b, + b, b; +} + diff --git a/test/window9.test b/test/window9.test index 46d746c4f..c342a4d79 100644 --- a/test/window9.test +++ b/test/window9.test @@ -255,7 +255,7 @@ do_execsql_test 8.2 { do_catchsql_test 8.3 { SELECT min( max((SELECT x FROM v1)) ) OVER() -} {1 {misuse of aggregate: max()}} +} {0 0} do_execsql_test 8.4 { SELECT( @@ -263,6 +263,6 @@ do_execsql_test 8.4 { SELECT sum( avg((SELECT x FROM v1)) ) OVER() ) FROM v1; -} {0.0} +} {0.0 0.0} finish_test |