namespace.slt 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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/namespace
  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 a(a INT)
  24. statement ok
  25. CREATE DATABASE public; CREATE TABLE public.public.t(a INT)
  26. # "public" with the current database designates the public schema
  27. query T
  28. SHOW TABLES FROM public
  29. ----
  30. a
  31. # To access all tables in database "public", one must specify
  32. # its public schema explicitly.
  33. query T
  34. SHOW TABLES FROM public.public
  35. ----
  36. t
  37. # Of course one can also list the tables in "public" by making it the
  38. # current database.
  39. statement ok
  40. SET database = public
  41. query T
  42. SHOW TABLES
  43. ----
  44. t
  45. statement ok
  46. SET database = test; DROP DATABASE public
  47. # Unqualified pg_type resolves from pg_catalog.
  48. query T
  49. SELECT typname FROM pg_type WHERE typname = 'date'
  50. ----
  51. date
  52. # Override table and check name resolves properly.
  53. statement ok
  54. SET search_path=public,pg_catalog
  55. statement ok
  56. CREATE TABLE pg_type(x INT); INSERT INTO pg_type VALUES(42)
  57. query I
  58. SELECT x FROM pg_type
  59. ----
  60. 42
  61. # Leave database, check name resolves to default.
  62. # The expected error can only occur on the virtual pg_type, not the physical one.
  63. query error cannot access virtual schema in anonymous database
  64. SET database = ''; SELECT * FROM pg_type
  65. # Go to different database, check name still resolves to default.
  66. query T
  67. CREATE DATABASE foo; SET database = foo; SELECT typname FROM pg_type WHERE typname = 'date'
  68. ----
  69. date
  70. # Verify that pg_catalog at the beginning of the search path takes precedence.
  71. query T
  72. SET database = test; SET search_path = pg_catalog,public; SELECT typname FROM pg_type WHERE typname = 'date'
  73. ----
  74. date
  75. # Now set the search path to the testdb, placing pg_catalog explicitly
  76. # at the end.
  77. query I
  78. SET search_path = public,pg_catalog; SELECT x FROM pg_type
  79. ----
  80. 42
  81. statement ok
  82. DROP TABLE pg_type; RESET search_path; SET database = test
  83. # Unqualified index name resolution.
  84. statement ok
  85. ALTER INDEX "primary" RENAME TO a_pk
  86. # Schema-qualified index name resolution.
  87. statement ok
  88. ALTER INDEX public.a_pk RENAME TO a_pk2
  89. # DB-qualified index name resolution (CRDB 1.x compat).
  90. statement ok
  91. ALTER INDEX test.a_pk2 RENAME TO a_pk3
  92. statement ok
  93. CREATE DATABASE public; CREATE TABLE public.public.t(a INT)
  94. # We can't see the DB "public" with DB-qualified index name resolution.
  95. statement error index "primary" does not exist
  96. ALTER INDEX public."primary" RENAME TO t_pk
  97. # But we can see it with sufficient qualification.
  98. statement ok
  99. ALTER INDEX public.public."primary" RENAME TO t_pk
  100. # If the search path is invalid, we get a special error.
  101. statement ok
  102. SET search_path = invalid
  103. statement error schema or database was not found while searching index: "a_pk3"
  104. ALTER INDEX a_pk3 RENAME TO a_pk4
  105. # But qualification resolves the problem.
  106. statement ok
  107. ALTER INDEX public.a_pk3 RENAME TO a_pk4