pg_get_viewdef.slt 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. #
  10. # This file is derived from the logic test suite in CockroachDB. The
  11. # original file was retrieved on June 10, 2019 from:
  12. #
  13. # The original source code is subject to the terms of the Apache
  14. # 2.0 license, a copy of which can be found in the LICENSE file at the
  15. # root of this repository.
  16. # Start from a pristine server
  17. reset-server
  18. statement ok
  19. CREATE TABLE t (a int, b int, c int)
  20. statement ok
  21. CREATE VIEW t_view AS SELECT t.a, b FROM t
  22. # Test pg_get_viewdef(view_name)
  23. query T
  24. SELECT pg_get_viewdef('doesnotexist')
  25. ----
  26. NULL
  27. query T
  28. SELECT pg_get_viewdef('t_view')
  29. ----
  30. SELECT "t"."a", "b" FROM [u1 AS "materialize"."public"."t"];
  31. # Test pg_get_viewdef(view_oid)
  32. query T
  33. SELECT pg_get_viewdef(0)
  34. ----
  35. NULL
  36. query T
  37. SELECT pg_get_viewdef('t_view'::regclass::oid)
  38. ----
  39. SELECT "t"."a", "b" FROM [u1 AS "materialize"."public"."t"];
  40. # Test pg_get_viewdef(view_name, pretty)
  41. query T
  42. SELECT pg_get_viewdef('doesnotexist', true)
  43. ----
  44. NULL
  45. query T
  46. SELECT pg_get_viewdef('doesnotexist', false)
  47. ----
  48. NULL
  49. query T
  50. SELECT pg_get_viewdef('t_view', true)
  51. ----
  52. SELECT "t"."a", "b" FROM [u1 AS "materialize"."public"."t"];
  53. query T
  54. SELECT pg_get_viewdef('t_view', false)
  55. ----
  56. SELECT "t"."a", "b" FROM [u1 AS "materialize"."public"."t"];
  57. # Test pg_get_viewdef(view_oid, pretty)
  58. query T
  59. SELECT pg_get_viewdef(0, true)
  60. ----
  61. NULL
  62. query T
  63. SELECT pg_get_viewdef(0, false)
  64. ----
  65. NULL
  66. query T
  67. SELECT pg_get_viewdef('t_view'::regclass::oid, true)
  68. ----
  69. SELECT "t"."a", "b" FROM [u1 AS "materialize"."public"."t"];
  70. query T
  71. SELECT pg_get_viewdef('t_view'::regclass::oid, false)
  72. ----
  73. SELECT "t"."a", "b" FROM [u1 AS "materialize"."public"."t"];
  74. # Test pg_get_viewdef(view_oid, wrap_column)
  75. query T
  76. SELECT pg_get_viewdef(0, 80)
  77. ----
  78. NULL
  79. query T
  80. SELECT pg_get_viewdef('t_view'::regclass::oid, 80)
  81. ----
  82. SELECT "t"."a", "b" FROM [u1 AS "materialize"."public"."t"];
  83. # Test retrieving view definition after table rename
  84. statement ok
  85. ALTER TABLE t RENAME TO t2
  86. query T
  87. SELECT pg_get_viewdef('t_view'::regclass::oid)
  88. ----
  89. SELECT "t2"."a", "b" FROM [u1 AS "materialize"."public"."t2"];