select_all_group_by.slt 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. mode cockroach
  10. statement ok
  11. CREATE TABLE foo (a integer)
  12. statement ok
  13. INSERT INTO foo VALUES (37)
  14. statement ok
  15. CREATE TABLE bar (a integer, b integer)
  16. statement ok
  17. INSERT INTO bar VALUES (37, 42), (37, 42)
  18. query II
  19. SELECT *, count(*) FROM foo GROUP BY a
  20. ----
  21. 37 1
  22. query II
  23. SELECT *, count(*) FROM foo GROUP BY a, a, a + 1
  24. ----
  25. 37 1
  26. query I
  27. SELECT a FROM foo GROUP BY a, foo.a
  28. ----
  29. 37
  30. statement error column "bar.b" must appear in the GROUP BY clause or be used in an aggregate function
  31. SELECT *, count(*) FROM bar GROUP BY a
  32. query II
  33. SELECT a, count(*) FROM bar GROUP BY a
  34. ----
  35. 37 2
  36. query II
  37. SELECT * FROM bar GROUP BY a, b
  38. ----
  39. 37 42
  40. statement ok
  41. CREATE TABLE quux (a integer)
  42. query I
  43. SELECT count(a) FROM quux WHERE a < 0
  44. ----
  45. 0
  46. query I
  47. SELECT count(*) FROM quux WHERE a < 0
  48. ----
  49. 0
  50. statement ok
  51. INSERT INTO quux VALUES (37), (NULL)
  52. query I
  53. SELECT count(*) FROM quux
  54. ----
  55. 2
  56. query I
  57. SELECT count(a) FROM quux
  58. ----
  59. 1
  60. query I
  61. SELECT count(a) FROM quux WHERE a < 0
  62. ----
  63. 0
  64. query I
  65. SELECT count(*) FROM quux WHERE a < 0
  66. ----
  67. 0
  68. query I
  69. SELECT sum(a) FROM quux
  70. ----
  71. 37
  72. query I
  73. SELECT sum(a) FROM quux WHERE a < 0
  74. ----
  75. NULL