id.slt 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. mode cockroach
  10. # Start from a pristine server
  11. reset-server
  12. statement ok
  13. CREATE TABLE x (a int)
  14. statement ok
  15. INSERT INTO x VALUES (1), (2), (3)
  16. query T
  17. SELECT id FROM mz_catalog.mz_tables WHERE name = 'x'
  18. ----
  19. u1
  20. query I rowsort
  21. SELECT a FROM x
  22. ----
  23. 1
  24. 2
  25. 3
  26. query I rowsort
  27. SELECT a FROM [u1 AS materialize.public.y]
  28. ----
  29. 1
  30. 2
  31. 3
  32. # Renaming the table to something different.
  33. # Referring to it by its "true" name should not work.
  34. statement error column "x.a" does not exist
  35. SELECT x.a FROM [u1 AS materialize.public.y]
  36. # Referring to it by its assigned name should work.
  37. query I rowsort
  38. SELECT y.a FROM [u1 AS materialize.public.y]
  39. ----
  40. 1
  41. 2
  42. 3
  43. statement error invalid id
  44. SELECT y.a FROM [u6 AS materialize.public.y]
  45. statement error couldn't parse id
  46. SELECT y.a FROM [xx AS materialize.public.y]
  47. statement error invalid digit
  48. SELECT y.a FROM [ux AS materialize.public.y]
  49. statement ok
  50. CREATE VIEW foo AS SELECT * FROM x
  51. mode standard
  52. # If the name in the catalog matches that which is specified in the view
  53. # definition, we should output it as its (fully qualified) name.
  54. query TT
  55. SHOW CREATE VIEW foo
  56. ----
  57. materialize.public.foo
  58. CREATE VIEW materialize.public.foo AS SELECT * FROM materialize.public.x;
  59. statement ok
  60. DROP VIEW foo;
  61. statement ok
  62. CREATE VIEW foo AS SELECT * FROM [u1 AS materialize.public.x]
  63. query TT
  64. SHOW CREATE VIEW foo
  65. ----
  66. materialize.public.foo
  67. CREATE VIEW materialize.public.foo AS SELECT * FROM materialize.public.x;
  68. # If the name *differs*, fall back to the id version.
  69. statement ok
  70. DROP VIEW foo;
  71. statement ok
  72. CREATE VIEW foo AS SELECT * FROM [u1 AS materialize.public.y]
  73. query TT
  74. SHOW CREATE VIEW foo
  75. ----
  76. materialize.public.foo
  77. CREATE VIEW materialize.public.foo AS SELECT * FROM [u1 AS materialize.public.y];