ordinality.slt 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. # Copyright 2015 - 2019 The Cockroach Authors. All rights reserved.
  2. # Copyright Materialize, Inc. and contributors. All rights reserved.
  3. #
  4. # Use of this software is governed by the Business Source License
  5. # included in the LICENSE file at the root of this repository.
  6. #
  7. # As of the Change Date specified in that file, in accordance with
  8. # the Business Source License, use of this software will be governed
  9. # by the Apache License, Version 2.0.
  10. #
  11. # This file is derived from the logic test suite in CockroachDB. The
  12. # original file was retrieved on June 10, 2019 from:
  13. #
  14. # https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/ordinality
  15. #
  16. # The original source code is subject to the terms of the Apache
  17. # 2.0 license, a copy of which can be found in the LICENSE file at the
  18. # root of this repository.
  19. # not supported yet
  20. halt
  21. mode cockroach
  22. query TI colnames
  23. SELECT * FROM (VALUES ('a'), ('b')) WITH ORDINALITY AS x(name, i)
  24. ----
  25. name i
  26. a 1
  27. b 2
  28. query I colnames
  29. SELECT ordinality FROM (VALUES ('a'), ('b')) WITH ORDINALITY
  30. ----
  31. ordinality
  32. 1
  33. 2
  34. statement ok
  35. CREATE TABLE foo (x CHAR PRIMARY KEY)
  36. statement ok
  37. INSERT INTO foo(x) VALUES ('a'), ('b')
  38. query TI
  39. SELECT * FROM foo WITH ORDINALITY
  40. ----
  41. a 1
  42. b 2
  43. query TI
  44. SELECT * FROM foo WITH ORDINALITY LIMIT 1
  45. ----
  46. a 1
  47. query I
  48. SELECT max(ordinality) FROM foo WITH ORDINALITY
  49. ----
  50. 2
  51. query TITI rowsort
  52. SELECT * FROM foo WITH ORDINALITY AS a, foo WITH ORDINALITY AS b
  53. ----
  54. a 1 a 1
  55. a 1 b 2
  56. b 2 a 1
  57. b 2 b 2
  58. query TI
  59. SELECT * FROM (SELECT x||x FROM foo) WITH ORDINALITY
  60. ----
  61. aa 1
  62. bb 2
  63. query TII
  64. SELECT * FROM (SELECT x, ordinality*2 FROM foo WITH ORDINALITY AS a) JOIN foo WITH ORDINALITY AS b USING (x)
  65. ----
  66. a 2 1
  67. b 4 2
  68. statement ok
  69. INSERT INTO foo(x) VALUES ('c')
  70. query TI
  71. SELECT * FROM foo WITH ORDINALITY WHERE x > 'a'
  72. ----
  73. b 2
  74. c 3
  75. query TI
  76. SELECT * FROM foo WITH ORDINALITY WHERE ordinality > 1 ORDER BY ordinality DESC
  77. ----
  78. c 3
  79. b 2
  80. query TI
  81. SELECT * FROM (SELECT * FROM foo WHERE x > 'a') WITH ORDINALITY
  82. ----
  83. b 1
  84. c 2
  85. query B
  86. SELECT ordinality = row_number() OVER () FROM foo WITH ORDINALITY
  87. ----
  88. true
  89. true
  90. true
  91. # Regression test for cockroach#33659
  92. statement ok
  93. TABLE [SHOW ZONE CONFIGURATIONS] WITH ORDINALITY