1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-29 08:01:23 +03:00

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
This commit is contained in:
dan
2020-06-09 17:45:48 +00:00
parent cfb8bf6a50
commit ed41a96bc1
5 changed files with 79 additions and 13 deletions

View File

@ -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;
}

View File

@ -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