1
0

tkt2942.test 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # 2008 February 15
  2. #
  3. # The author disclaims copyright to this source code. In place of
  4. # a legal notice, here is a blessing:
  5. #
  6. # May you do good and not evil.
  7. # May you find forgiveness for yourself and forgive others.
  8. # May you share freely, never taking more than you give.
  9. #
  10. #***********************************************************************
  11. #
  12. # Ticket #2942.
  13. #
  14. # Queries of the form:
  15. #
  16. # SELECT group_concat(x) FROM (SELECT * FROM table ORDER BY 1);
  17. #
  18. # The ORDER BY would be dropped by the query flattener. This used
  19. # to not matter because aggregate functions sum(), min(), max(), avg(),
  20. # and so forth give the same result regardless of the order of inputs.
  21. # But with the addition of the group_concat() function, suddenly the
  22. # order does matter.
  23. #
  24. # $Id: tkt2942.test,v 1.1 2008/02/15 14:33:04 drh Exp $
  25. #
  26. set testdir [file dirname $argv0]
  27. source $testdir/tester.tcl
  28. ifcapable !subquery {
  29. finish_test
  30. return
  31. }
  32. do_test tkt2942.1 {
  33. execsql {
  34. create table t1(num int);
  35. insert into t1 values (2);
  36. insert into t1 values (1);
  37. insert into t1 values (3);
  38. insert into t1 values (4);
  39. SELECT group_concat(num) FROM (SELECT num FROM t1 ORDER BY num DESC);
  40. }
  41. } {4,3,2,1}
  42. do_test tkt2942.2 {
  43. execsql {
  44. SELECT group_concat(num) FROM (SELECT num FROM t1 ORDER BY num);
  45. }
  46. } {1,2,3,4}
  47. do_test tkt2942.3 {
  48. execsql {
  49. SELECT group_concat(num) FROM (SELECT num FROM t1);
  50. }
  51. } {2,1,3,4}
  52. do_test tkt2942.4 {
  53. execsql {
  54. SELECT group_concat(num) FROM (SELECT num FROM t1 ORDER BY rowid DESC);
  55. }
  56. } {4,3,1,2}
  57. finish_test