mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-29 08:01:23 +03:00
min() ignores NULL values. Ticket #800. (CVS 1802)
FossilOrigin-Name: 166234a2b61e1d6a501e48dde1caec0a02bec90b
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.27 2004/06/29 13:18:24 danielk1977 Exp $
|
||||
# $Id: func.test,v 1.28 2004/07/18 20:52:32 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@ -251,7 +251,7 @@ do_test func-8.1 {
|
||||
execsql {
|
||||
SELECT sum(a), count(a), round(avg(a),2), min(a), max(a), count(*) FROM t2;
|
||||
}
|
||||
} {68236 3 22745.33 {} 67890 5}
|
||||
} {68236 3 22745.33 1 67890 5}
|
||||
do_test func-8.2 {
|
||||
execsql {
|
||||
SELECT max('z+'||a||'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP') FROM t2;
|
||||
@ -262,7 +262,7 @@ do_test func-8.3 {
|
||||
CREATE TEMP TABLE t3 AS SELECT a FROM t2 ORDER BY a DESC;
|
||||
SELECT min('z+'||a||'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP') FROM t3;
|
||||
}
|
||||
} {{}}
|
||||
} {z+1abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP}
|
||||
do_test func-8.4 {
|
||||
execsql {
|
||||
SELECT max('z+'||a||'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP') FROM t3;
|
||||
|
@ -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
|
||||
|
@ -100,7 +100,7 @@ do_test null-3.1 {
|
||||
select count(*), count(b), count(c), sum(b), sum(c),
|
||||
avg(b), avg(c), min(b), max(b) from t1;
|
||||
}
|
||||
} {7 4 6 2 3 0.5 0.5 {} 1}
|
||||
} {7 4 6 2 3 0.5 0.5 0 1}
|
||||
|
||||
# Check to see how WHERE clauses handle NULL values. A NULL value
|
||||
# is the same as UNKNOWN. The WHERE clause should only select those
|
||||
|
@ -11,7 +11,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this file is testing the SELECT statement.
|
||||
#
|
||||
# $Id: select1.test,v 1.33 2004/06/24 00:20:05 danielk1977 Exp $
|
||||
# $Id: select1.test,v 1.34 2004/07/18 20:52:32 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@ -159,7 +159,7 @@ do_test select1-2.8 {
|
||||
} {0 {11 33}}
|
||||
do_test select1-2.8.1 {
|
||||
execsql {SELECT coalesce(min(a),'xyzzy') FROM t3}
|
||||
} {xyzzy}
|
||||
} {11}
|
||||
do_test select1-2.8.2 {
|
||||
execsql {SELECT min(coalesce(a,'xyzzy')) FROM t3}
|
||||
} {11}
|
||||
|
Reference in New Issue
Block a user