rename_constraint.slt 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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/rename_constraint
  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 t (
  24. x INT, y INT,
  25. CONSTRAINT cu UNIQUE (x),
  26. CONSTRAINT cc CHECK (x > 10),
  27. CONSTRAINT cf FOREIGN KEY (x) REFERENCES t(x)
  28. )
  29. query T
  30. SELECT create_statement FROM [SHOW CREATE t]
  31. ----
  32. CREATE TABLE t (
  33. x INT8 NULL,
  34. y INT8 NULL,
  35. CONSTRAINT cf FOREIGN KEY (x) REFERENCES t (x),
  36. UNIQUE INDEX cu (x ASC),
  37. FAMILY "primary" (x, y, rowid),
  38. CONSTRAINT cc CHECK (x > 10)
  39. )
  40. query TT
  41. SELECT conname, contype FROM pg_catalog.pg_constraint ORDER BY conname
  42. ----
  43. cc c
  44. cf f
  45. cu u
  46. subtest rename_works
  47. statement ok
  48. ALTER TABLE t RENAME CONSTRAINT cu TO cu2,
  49. RENAME CONSTRAINT cf TO cf2,
  50. RENAME CONSTRAINT cc TO cc2
  51. query T
  52. SELECT create_statement FROM [SHOW CREATE t]
  53. ----
  54. CREATE TABLE t (
  55. x INT8 NULL,
  56. y INT8 NULL,
  57. CONSTRAINT cf2 FOREIGN KEY (x) REFERENCES t (x),
  58. UNIQUE INDEX cu2 (x ASC),
  59. FAMILY "primary" (x, y, rowid),
  60. CONSTRAINT cc2 CHECK (x > 10)
  61. )
  62. query TT
  63. SELECT conname, contype FROM pg_catalog.pg_constraint ORDER BY conname
  64. ----
  65. cc2 c
  66. cf2 f
  67. cu2 u
  68. subtest duplicate_constraints
  69. statement error duplicate constraint
  70. ALTER TABLE t RENAME CONSTRAINT cu2 TO cf2
  71. statement error duplicate constraint
  72. ALTER TABLE t RENAME CONSTRAINT cu2 TO cc2
  73. statement error duplicate constraint
  74. ALTER TABLE t RENAME CONSTRAINT cf2 TO cu2
  75. statement error duplicate constraint
  76. ALTER TABLE t RENAME CONSTRAINT cf2 TO cc2
  77. statement error duplicate constraint
  78. ALTER TABLE t RENAME CONSTRAINT cc2 TO cf2
  79. statement error duplicate constraint
  80. ALTER TABLE t RENAME CONSTRAINT cc2 TO cu2
  81. subtest multiple_renames
  82. statement ok
  83. ALTER TABLE t RENAME CONSTRAINT cu2 TO cu3,
  84. RENAME CONSTRAINT cc2 TO cc3,
  85. RENAME CONSTRAINT cf2 TO cf3,
  86. RENAME CONSTRAINT cu3 TO cu4,
  87. RENAME CONSTRAINT cc3 TO cc4,
  88. RENAME CONSTRAINT cf3 TO cf4
  89. query T
  90. SELECT create_statement FROM [SHOW CREATE t]
  91. ----
  92. CREATE TABLE t (
  93. x INT8 NULL,
  94. y INT8 NULL,
  95. CONSTRAINT cf4 FOREIGN KEY (x) REFERENCES t (x),
  96. UNIQUE INDEX cu4 (x ASC),
  97. FAMILY "primary" (x, y, rowid),
  98. CONSTRAINT cc4 CHECK (x > 10)
  99. )
  100. query TT
  101. SELECT conname, contype FROM pg_catalog.pg_constraint ORDER BY conname
  102. ----
  103. cc4 c
  104. cf4 f
  105. cu4 u