ordinal_references.slt 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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/ordinal_references
  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. statement ok
  23. CREATE TABLE foo(a INT, b CHAR)
  24. query I
  25. INSERT INTO foo(a, b) VALUES (1,'c'), (2,'b'), (3,'a') RETURNING @1
  26. ----
  27. 1
  28. 2
  29. 3
  30. query error invalid column ordinal
  31. SELECT @0 FROM foo
  32. query error invalid column ordinal
  33. SELECT @42 FROM foo
  34. query TI rowsort
  35. SELECT @2, @1 FROM foo
  36. ----
  37. c 1
  38. b 2
  39. a 3
  40. # Traditional SQL ordinals refer to the render list.
  41. query TI
  42. SELECT b, a FROM foo ORDER BY 1
  43. ----
  44. a 3
  45. b 2
  46. c 1
  47. # CockroachDB column ordinals refer to the data source.
  48. query TI
  49. SELECT b, a FROM foo ORDER BY @1
  50. ----
  51. c 1
  52. b 2
  53. a 3
  54. query TI
  55. SELECT b, a FROM foo ORDER BY @1 % 2, a
  56. ----
  57. b 2
  58. c 1
  59. a 3
  60. statement ok
  61. INSERT INTO foo(a, b) VALUES (4, 'c'), (5, 'c'), (6, 'c')
  62. query R
  63. SELECT sum(a) AS s FROM foo GROUP BY @1 ORDER BY s
  64. ----
  65. 1
  66. 2
  67. 3
  68. 4
  69. 5
  70. 6
  71. query R
  72. SELECT sum(a) AS s FROM foo GROUP BY @2 ORDER BY s
  73. ----
  74. 2
  75. 3
  76. 16
  77. statement error column reference @1 not allowed in this context
  78. INSERT INTO foo(a, b) VALUES (@1, @2)
  79. query error column reference @485 not allowed in this context
  80. VALUES (@485)
  81. query error column reference @1 not allowed in this context
  82. SELECT * FROM foo LIMIT @1
  83. query error column reference @1 not allowed in this context
  84. SELECT * FROM foo OFFSET @1