OLD | NEW |
1 # 2001 September 15 | 1 # 2001 September 15 |
2 # | 2 # |
3 # The author disclaims copyright to this source code. In place of | 3 # The author disclaims copyright to this source code. In place of |
4 # a legal notice, here is a blessing: | 4 # a legal notice, here is a blessing: |
5 # | 5 # |
6 # May you do good and not evil. | 6 # May you do good and not evil. |
7 # May you find forgiveness for yourself and forgive others. | 7 # May you find forgiveness for yourself and forgive others. |
8 # May you share freely, never taking more than you give. | 8 # May you share freely, never taking more than you give. |
9 # | 9 # |
10 #*********************************************************************** | 10 #*********************************************************************** |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 ) | 550 ) |
551 } $err | 551 } $err |
552 do_catchsql_test 10.8 { | 552 do_catchsql_test 10.8 { |
553 SELECT * FROM ( | 553 SELECT * FROM ( |
554 SELECT * FROM k UNION ALL | 554 SELECT * FROM k UNION ALL |
555 SELECT * FROM t UNION ALL | 555 SELECT * FROM t UNION ALL |
556 SELECT l,m,l FROM j | 556 SELECT l,m,l FROM j |
557 ) | 557 ) |
558 } $err | 558 } $err |
559 | 559 |
| 560 # 2015-02-09 Ticket [2f7170d73bf9abf80339187aa3677dce3dbcd5ca] |
| 561 # "misuse of aggregate" error if aggregate column from FROM |
| 562 # subquery is used in correlated subquery |
| 563 # |
| 564 do_execsql_test 11.1 { |
| 565 DROP TABLE IF EXISTS t1; |
| 566 CREATE TABLE t1(w INT, x INT); |
| 567 INSERT INTO t1(w,x) |
| 568 VALUES(1,10),(2,20),(3,30), |
| 569 (2,21),(3,31), |
| 570 (3,32); |
| 571 CREATE INDEX t1wx ON t1(w,x); |
| 572 |
| 573 DROP TABLE IF EXISTS t2; |
| 574 CREATE TABLE t2(w INT, y VARCHAR(8)); |
| 575 INSERT INTO t2(w,y) VALUES(1,'one'),(2,'two'),(3,'three'),(4,'four'); |
| 576 CREATE INDEX t2wy ON t2(w,y); |
| 577 |
| 578 SELECT cnt, xyz, (SELECT y FROM t2 WHERE w=cnt), '|' |
| 579 FROM (SELECT count(*) AS cnt, w AS xyz FROM t1 GROUP BY 2) |
| 580 ORDER BY cnt, xyz; |
| 581 } {1 1 one | 2 2 two | 3 3 three |} |
| 582 do_execsql_test 11.2 { |
| 583 SELECT cnt, xyz, lower((SELECT y FROM t2 WHERE w=cnt)), '|' |
| 584 FROM (SELECT count(*) AS cnt, w AS xyz FROM t1 GROUP BY 2) |
| 585 ORDER BY cnt, xyz; |
| 586 } {1 1 one | 2 2 two | 3 3 three |} |
| 587 do_execsql_test 11.3 { |
| 588 SELECT cnt, xyz, '|' |
| 589 FROM (SELECT count(*) AS cnt, w AS xyz FROM t1 GROUP BY 2) |
| 590 WHERE (SELECT y FROM t2 WHERE w=cnt)!='two' |
| 591 ORDER BY cnt, xyz; |
| 592 } {1 1 | 3 3 |} |
| 593 do_execsql_test 11.4 { |
| 594 SELECT cnt, xyz, '|' |
| 595 FROM (SELECT count(*) AS cnt, w AS xyz FROM t1 GROUP BY 2) |
| 596 ORDER BY lower((SELECT y FROM t2 WHERE w=cnt)); |
| 597 } {1 1 | 3 3 | 2 2 |} |
| 598 do_execsql_test 11.5 { |
| 599 SELECT cnt, xyz, |
| 600 CASE WHEN (SELECT y FROM t2 WHERE w=cnt)=='two' |
| 601 THEN 'aaa' ELSE 'bbb' |
| 602 END, '|' |
| 603 FROM (SELECT count(*) AS cnt, w AS xyz FROM t1 GROUP BY 2) |
| 604 ORDER BY +cnt; |
| 605 } {1 1 bbb | 2 2 aaa | 3 3 bbb |} |
| 606 |
| 607 do_execsql_test 11.100 { |
| 608 DROP TABLE t1; |
| 609 DROP TABLE t2; |
| 610 CREATE TABLE t1(x); |
| 611 CREATE TABLE t2(y, z); |
| 612 SELECT ( SELECT y FROM t2 WHERE z = cnt ) |
| 613 FROM ( SELECT count(*) AS cnt FROM t1 ); |
| 614 } {{}} |
| 615 |
560 | 616 |
561 finish_test | 617 finish_test |
OLD | NEW |