mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-08 14:02:16 +03:00
SUM returns NULL when it has no inputs. Ticket #1413. (CVS 2678)
FossilOrigin-Name: 6281859425d39c11d82875301fefafad1f08416d
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this file is testing built-in functions.
|
||||
#
|
||||
# $Id: func.test,v 1.39 2005/09/08 19:45:58 drh Exp $
|
||||
# $Id: func.test,v 1.40 2005/09/08 20:37:44 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -513,14 +513,14 @@ do_test func-18.2 {
|
||||
}
|
||||
} {9902.0}
|
||||
|
||||
# The sum of nothing is 0. But the sum of all NULLs is NULL.
|
||||
# The sum of nothing is NULL. But the sum of all NULLs is NULL.
|
||||
#
|
||||
do_test func-18.3 {
|
||||
execsql {
|
||||
DELETE FROM t5;
|
||||
SELECT sum(x) FROM t5;
|
||||
}
|
||||
} {0}
|
||||
} {{}}
|
||||
do_test func-18.4 {
|
||||
execsql {
|
||||
INSERT INTO t5 VALUES(NULL);
|
||||
|
@@ -12,7 +12,7 @@
|
||||
# focus of this file is testing aggregate functions and the
|
||||
# GROUP BY and HAVING clauses of SELECT statements.
|
||||
#
|
||||
# $Id: select3.test,v 1.15 2005/09/08 12:57:28 drh Exp $
|
||||
# $Id: select3.test,v 1.16 2005/09/08 20:37:44 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -233,7 +233,7 @@ do_test select3-7.2 {
|
||||
execsql {
|
||||
SELECT a, sum(b) FROM t2 WHERE b=5;
|
||||
}
|
||||
} {{} 0}
|
||||
} {{} {}}
|
||||
|
||||
|
||||
finish_test
|
||||
|
@@ -12,7 +12,7 @@
|
||||
# focus of this file is testing aggregate functions and the
|
||||
# GROUP BY and HAVING clauses of SELECT statements.
|
||||
#
|
||||
# $Id: select5.test,v 1.12 2005/09/08 10:37:01 drh Exp $
|
||||
# $Id: select5.test,v 1.13 2005/09/08 20:37:44 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -118,7 +118,7 @@ do_test select5-4.5 {
|
||||
execsql {
|
||||
SELECT sum(x) FROM t1 WHERE x>100
|
||||
}
|
||||
} {0}
|
||||
} {{}}
|
||||
|
||||
# Some tests for queries with a GROUP BY clause but no aggregate functions.
|
||||
#
|
||||
|
@@ -93,7 +93,8 @@ ifcapable subquery {
|
||||
BEGIN
|
||||
INSERT INTO rlog VALUES ( (SELECT coalesce(max(idx),0) + 1 FROM rlog),
|
||||
old.a, old.b,
|
||||
(SELECT sum(a) FROM tbl), (SELECT sum(b) FROM tbl),
|
||||
(SELECT coalesce(sum(a),0) FROM tbl),
|
||||
(SELECT coalesce(sum(b),0) FROM tbl),
|
||||
new.a, new.b);
|
||||
END;
|
||||
|
||||
@@ -101,7 +102,8 @@ ifcapable subquery {
|
||||
BEGIN
|
||||
INSERT INTO rlog VALUES ( (SELECT coalesce(max(idx),0) + 1 FROM rlog),
|
||||
old.a, old.b,
|
||||
(SELECT sum(a) FROM tbl), (SELECT sum(b) FROM tbl),
|
||||
(SELECT coalesce(sum(a),0) FROM tbl),
|
||||
(SELECT coalesce(sum(b),0) FROM tbl),
|
||||
new.a, new.b);
|
||||
END;
|
||||
|
||||
@@ -110,7 +112,8 @@ ifcapable subquery {
|
||||
BEGIN
|
||||
INSERT INTO clog VALUES ( (SELECT coalesce(max(idx),0) + 1 FROM clog),
|
||||
old.a, old.b,
|
||||
(SELECT sum(a) FROM tbl), (SELECT sum(b) FROM tbl),
|
||||
(SELECT coalesce(sum(a),0) FROM tbl),
|
||||
(SELECT coalesce(sum(b),0) FROM tbl),
|
||||
new.a, new.b);
|
||||
END;
|
||||
}
|
||||
@@ -140,7 +143,8 @@ ifcapable subquery {
|
||||
BEGIN
|
||||
INSERT INTO rlog VALUES ( (SELECT coalesce(max(idx),0) + 1 FROM rlog),
|
||||
old.a, old.b,
|
||||
(SELECT sum(a) FROM tbl), (SELECT sum(b) FROM tbl),
|
||||
(SELECT coalesce(sum(a),0) FROM tbl),
|
||||
(SELECT coalesce(sum(b),0) FROM tbl),
|
||||
0, 0);
|
||||
END;
|
||||
|
||||
@@ -148,7 +152,8 @@ ifcapable subquery {
|
||||
BEGIN
|
||||
INSERT INTO rlog VALUES ( (SELECT coalesce(max(idx),0) + 1 FROM rlog),
|
||||
old.a, old.b,
|
||||
(SELECT sum(a) FROM tbl), (SELECT sum(b) FROM tbl),
|
||||
(SELECT coalesce(sum(a),0) FROM tbl),
|
||||
(SELECT coalesce(sum(b),0) FROM tbl),
|
||||
0, 0);
|
||||
END;
|
||||
}
|
||||
@@ -172,7 +177,8 @@ ifcapable subquery {
|
||||
BEGIN
|
||||
INSERT INTO rlog VALUES ( (SELECT coalesce(max(idx),0) + 1 FROM rlog),
|
||||
0, 0,
|
||||
(SELECT sum(a) FROM tbl), (SELECT sum(b) FROM tbl),
|
||||
(SELECT coalesce(sum(a),0) FROM tbl),
|
||||
(SELECT coalesce(sum(b),0) FROM tbl),
|
||||
new.a, new.b);
|
||||
END;
|
||||
|
||||
@@ -180,7 +186,8 @@ ifcapable subquery {
|
||||
BEGIN
|
||||
INSERT INTO rlog VALUES ( (SELECT coalesce(max(idx),0) + 1 FROM rlog),
|
||||
0, 0,
|
||||
(SELECT sum(a) FROM tbl), (SELECT sum(b) FROM tbl),
|
||||
(SELECT coalesce(sum(a),0) FROM tbl),
|
||||
(SELECT coalesce(sum(b),0) FROM tbl),
|
||||
new.a, new.b);
|
||||
END;
|
||||
}
|
||||
|
Reference in New Issue
Block a user