1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-30 19:03:16 +03:00

min() ignores NULL values. Ticket #800. (CVS 1802)

FossilOrigin-Name: 166234a2b61e1d6a501e48dde1caec0a02bec90b
This commit is contained in:
drh
2004-07-18 20:52:32 +00:00
parent e29b1a05a7
commit 9eb516c0eb
9 changed files with 97 additions and 34 deletions

View File

@ -13,7 +13,7 @@
# aggregate min() and max() functions and which are handled as
# as a special case.
#
# $Id: minmax.test,v 1.10 2004/06/24 00:20:05 danielk1977 Exp $
# $Id: minmax.test,v 1.11 2004/07/18 20:52:32 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -127,7 +127,7 @@ do_test minmax-4.1 {
SELECT coalesce(min(x+0),-1), coalesce(max(x+0),-1) FROM
(SELECT * FROM t1 UNION SELECT NULL as 'x', NULL as 'y')
}
} {-1 20}
} {1 20}
do_test minmax-4.2 {
execsql {
SELECT y, sum(x) FROM
@ -276,9 +276,8 @@ do_test minmax-9.2 {
}
} {{}}
# If there is a NULL in an aggregate max(), ignore it. If a NULL
# occurs in an aggregate min(), then the result will be NULL because
# NULL compares less than all other values.
# If there is a NULL in an aggregate max() or min(), ignore it. An
# aggregate min() or max() will only return NULL if all values are NULL.
#
do_test minmax-10.1 {
execsql {
@ -288,7 +287,7 @@ do_test minmax-10.1 {
INSERT INTO t6 VALUES(NULL);
SELECT coalesce(min(x),-1) FROM t6;
}
} {-1}
} {1}
do_test minmax-10.2 {
execsql {
SELECT max(x) FROM t6;
@ -299,11 +298,63 @@ do_test minmax-10.3 {
CREATE INDEX i6 ON t6(x);
SELECT coalesce(min(x),-1) FROM t6;
}
} {-1}
} {1}
do_test minmax-10.4 {
execsql {
SELECT max(x) FROM t6;
}
} {2}
do_test minmax-10.5 {
execsql {
DELETE FROM t6 WHERE x NOT NULL;
SELECT count(*) FROM t6;
}
} 1
do_test minmax-10.6 {
execsql {
SELECT count(x) FROM t6;
}
} 0
do_test minmax-10.7 {
execsql {
SELECT (SELECT min(x) FROM t6), (SELECT max(x) FROM t6);
}
} {{} {}}
do_test minmax-10.8 {
execsql {
SELECT min(x), max(x) FROM t6;
}
} {{} {}}
do_test minmax-10.9 {
execsql {
INSERT INTO t6 SELECT * FROM t6;
INSERT INTO t6 SELECT * FROM t6;
INSERT INTO t6 SELECT * FROM t6;
INSERT INTO t6 SELECT * FROM t6;
INSERT INTO t6 SELECT * FROM t6;
INSERT INTO t6 SELECT * FROM t6;
INSERT INTO t6 SELECT * FROM t6;
INSERT INTO t6 SELECT * FROM t6;
INSERT INTO t6 SELECT * FROM t6;
INSERT INTO t6 SELECT * FROM t6;
SELECT count(*) FROM t6;
}
} 1024
do_test minmax-10.10 {
execsql {
SELECT count(x) FROM t6;
}
} 0
do_test minmax-10.11 {
execsql {
SELECT (SELECT min(x) FROM t6), (SELECT max(x) FROM t6);
}
} {{} {}}
do_test minmax-10.12 {
execsql {
SELECT min(x), max(x) FROM t6;
}
} {{} {}}
finish_test