mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-01 06:27:03 +03:00
Allow a HAVING clause on any aggregate query, even if there is no GROUP BY
clause. This brings SQLite into closer agreement with PostgreSQL and fixes the concern raised by [forum:/forumpost/1a7fea4651|forum post 1a7fea4651]. FossilOrigin-Name: 9322a7c21f1c22ba00e9b889223e89bc1591db6e561ce05091e905e98c1bf2b3
This commit is contained in:
@ -126,9 +126,12 @@ do_test count-2.7 {
|
||||
do_test count-2.8 {
|
||||
uses_op_count {SELECT count(*) FROM t2 WHERE a IS NOT NULL}
|
||||
} {0}
|
||||
do_test count-2.9 {
|
||||
catchsql {SELECT count(*) FROM t2 HAVING count(*)>1}
|
||||
} {1 {a GROUP BY clause is required before HAVING}}
|
||||
do_execsql_test count-2.9a {
|
||||
SELECT count(*) FROM t2 HAVING count(*)>1;
|
||||
} {}
|
||||
do_execsql_test count-2.9b {
|
||||
SELECT count(*) FROM t2 HAVING count(*)<10;
|
||||
} {0}
|
||||
do_test count-2.10 {
|
||||
uses_op_count {SELECT count(*) FROM (SELECT 1)}
|
||||
} {0}
|
||||
|
@ -119,10 +119,9 @@ do_test select3-2.14 {
|
||||
|
||||
# Cannot have a HAVING without a GROUP BY
|
||||
#
|
||||
do_test select3-3.1 {
|
||||
set v [catch {execsql {SELECT log, count(*) FROM t1 HAVING log>=4}} msg]
|
||||
lappend v $msg
|
||||
} {1 {a GROUP BY clause is required before HAVING}}
|
||||
do_execsql_test select3-3.1 {
|
||||
SELECT log, count(*) FROM t1 HAVING log>=4
|
||||
} {}
|
||||
|
||||
# Toss in some HAVING clauses
|
||||
#
|
||||
|
@ -2203,5 +2203,10 @@ do_catchsql_test 71.0 {
|
||||
ORDER BY b;
|
||||
} {/1 {.*}/}
|
||||
|
||||
do_execsql_test 72.1 {
|
||||
CREATE TABLE dual(dummy); INSERT INTO dual VALUES('X');
|
||||
CREATE VIEW v1(x,y) AS SELECT RANK() OVER (PARTITION BY 0), SUM(0) FROM dual;
|
||||
SELECT * FROM v1 WHERE true;
|
||||
} {1 0}
|
||||
|
||||
finish_test
|
||||
|
Reference in New Issue
Block a user