target_names.slt 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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/target_names
  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. mode cockroach
  20. statement ok
  21. CREATE TABLE t(a INT[], t STRING);
  22. # Simple expressions get the underlying column name as name.
  23. query ITTIIT colnames
  24. SELECT *, a, a[0], (((((((((a))))))))), t COLLATE "en_US" FROM t
  25. ----
  26. a t a a a t
  27. # Functions and function-like expressions get the function name.
  28. query ITTTTBTT colnames
  29. SELECT array_length(a, 1),
  30. nullif(a, a),
  31. row(1,2,3),
  32. coalesce(a,a),
  33. iferror(a, a),
  34. iserror(a),
  35. if(true, a, a),
  36. current_user
  37. FROM t
  38. ----
  39. array_length nullif row coalesce iferror iserror if current_user
  40. # Literals get named just "?column?" except for true/false which are handled specially.
  41. query ITRBBT colnames
  42. SELECT 123, '123', 123.0, TRUE, FALSE, NULL
  43. ----
  44. ?column? ?column? ?column? bool bool ?column?
  45. 123 123 123.0 true false NULL
  46. # Casts get the underlying expression name if there is one,
  47. # otherwise the name of the type.
  48. query IITI colnames
  49. SELECT t::INT, '123'::INT, t:::STRING, '123':::INT FROM t
  50. ----
  51. t int8 t int8
  52. # Field access gets the field name.
  53. query T colnames
  54. SELECT (pg_get_keywords()).word FROM t
  55. ----
  56. word
  57. # Array stuff is called "array"
  58. query TT colnames
  59. SELECT array[1,2,3], array(select 1)
  60. ----
  61. array array
  62. {1,2,3} {1}
  63. # EXISTS in subqueries called "exists"
  64. query B colnames
  65. SELECT EXISTS(SELECT * FROM t)
  66. ----
  67. exists
  68. false
  69. # CASE gets named after the ELSE branch, otherwise "case"
  70. query IIIII colnames
  71. SELECT CASE 1 WHEN 2 THEN 3 END,
  72. CASE 1 WHEN 2 THEN 3 ELSE a[0] END,
  73. CASE 1 WHEN 2 THEN 3 ELSE length(t) END,
  74. CASE 1 WHEN 2 THEN 3 ELSE (t||'a')::INT END,
  75. CASE 1 WHEN 2 THEN 3 ELSE 4 END
  76. FROM t
  77. ----
  78. case a length case case
  79. # Subqueries get named after the expression.
  80. query III colnames
  81. SELECT (SELECT 123 AS a),
  82. (VALUES (cos(1)::INT)),
  83. (SELECT cos(0)::INT)
  84. ----
  85. a column1 cos
  86. 123 0 1