select_search_path.slt 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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/select_search_path
  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. # Test that pg_catalog tables are accessible without qualifying table/view
  23. # names.
  24. query T
  25. SHOW TABLES
  26. ----
  27. # There's no table with default values in the default test database.
  28. query I
  29. SELECT count(DISTINCT(1)) FROM pg_attrdef
  30. ----
  31. 0
  32. query I
  33. SELECT count(DISTINCT(1)) FROM pg_attribute
  34. ----
  35. 1
  36. query I
  37. SELECT count(DISTINCT(1)) FROM pg_class
  38. ----
  39. 1
  40. query I
  41. SELECT count(DISTINCT(1)) FROM pg_namespace
  42. ----
  43. 1
  44. query I
  45. SELECT count(DISTINCT(1)) FROM pg_tables
  46. ----
  47. 1
  48. statement ok
  49. CREATE DATABASE t1
  50. statement ok
  51. CREATE TABLE t1.numbers (n INTEGER)
  52. statement ok
  53. CREATE DATABASE t2
  54. statement ok
  55. CREATE TABLE t2.words (w TEXT)
  56. # Test that we can query with unqualified table names from t1 and pg_catalog
  57. # (but not t2) when t1 is the session database.
  58. statement ok
  59. SET DATABASE = t1
  60. query I
  61. SELECT count(*) FROM numbers
  62. ----
  63. 0
  64. query error pq: relation "words" does not exist
  65. SELECT count(*) FROM words
  66. # There's no table with default values in t1.
  67. query I
  68. SELECT count(DISTINCT(1)) FROM pg_attrdef
  69. ----
  70. 1
  71. query I
  72. SELECT count(DISTINCT(1)) FROM pg_attribute
  73. ----
  74. 1
  75. query I
  76. SELECT count(DISTINCT(1)) FROM pg_class
  77. ----
  78. 1
  79. query I
  80. SELECT count(DISTINCT(1)) FROM pg_namespace
  81. ----
  82. 1
  83. query I
  84. SELECT count(DISTINCT(1)) FROM pg_tables
  85. ----
  86. 1
  87. # Test that we can query with unqualified table names from t2 and pg_catalog
  88. # (but not t1) when t2 is the session database.
  89. statement ok
  90. SET DATABASE = t2
  91. query error pq: relation "numbers" does not exist
  92. SELECT count(*) FROM numbers
  93. query I
  94. SELECT count(*) FROM words
  95. ----
  96. 0
  97. # There's no table with default values in t2.
  98. query I
  99. SELECT count(DISTINCT(1)) FROM pg_attrdef
  100. ----
  101. 1
  102. query I
  103. SELECT count(DISTINCT(1)) FROM pg_attribute
  104. ----
  105. 1
  106. query I
  107. SELECT count(DISTINCT(1)) FROM pg_class
  108. ----
  109. 1
  110. query I
  111. SELECT count(DISTINCT(1)) FROM pg_namespace
  112. ----
  113. 1
  114. query I
  115. SELECT count(DISTINCT(1)) FROM pg_tables
  116. ----
  117. 1
  118. # Test that current_schema reports the first valid entry in search_path, or
  119. # NULL if there is no such entry.
  120. statement ok
  121. SET search_path = nonexistent, public
  122. query T
  123. SELECT current_schema
  124. ----
  125. public
  126. statement ok
  127. SET search_path = nonexistent
  128. query T
  129. SELECT current_schema
  130. ----
  131. NULL
  132. # Test that current_schemas only reports the valid entries in
  133. # search_path.
  134. statement ok
  135. SET search_path = nonexistent, public
  136. query T
  137. SELECT current_schemas(false)
  138. ----
  139. {public}
  140. # Test that object creation targets the first valid entry in
  141. # search_path, not just the first entry.
  142. statement ok
  143. CREATE TABLE sometable(x INT); SELECT * FROM public.sometable