uuid.slt 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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/uuid
  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 u (token uuid PRIMARY KEY,
  24. token2 uuid,
  25. token3 uuid,
  26. UNIQUE INDEX i_token2 (token2))
  27. statement ok
  28. INSERT INTO u VALUES
  29. ('63616665-6630-3064-6465-616462656562', '{63616665-6630-3064-6465-616462656563}', b'kafef00ddeadbeed'),
  30. ('urn:uuid:63616665-6630-3064-6465-616462656564', '63616665-6630-3064-6465-616462656565'::uuid, b'kafef00ddeadbeee'),
  31. (b'cafef00ddeadbeef', '63616665-6630-3064-6465-616462656567', b'kafef00ddeadbeef')
  32. query TTT
  33. SELECT * FROM u ORDER BY token
  34. ----
  35. 63616665-6630-3064-6465-616462656562 63616665-6630-3064-6465-616462656563 6b616665-6630-3064-6465-616462656564
  36. 63616665-6630-3064-6465-616462656564 63616665-6630-3064-6465-616462656565 6b616665-6630-3064-6465-616462656565
  37. 63616665-6630-3064-6465-616462656566 63616665-6630-3064-6465-616462656567 6b616665-6630-3064-6465-616462656566
  38. query TTT
  39. SELECT * FROM u WHERE token < '63616665-6630-3064-6465-616462656564'::uuid
  40. ----
  41. 63616665-6630-3064-6465-616462656562 63616665-6630-3064-6465-616462656563 6b616665-6630-3064-6465-616462656564
  42. query TTT
  43. SELECT * FROM u WHERE token <= '63616665-6630-3064-6465-616462656564'::uuid ORDER BY token
  44. ----
  45. 63616665-6630-3064-6465-616462656562 63616665-6630-3064-6465-616462656563 6b616665-6630-3064-6465-616462656564
  46. 63616665-6630-3064-6465-616462656564 63616665-6630-3064-6465-616462656565 6b616665-6630-3064-6465-616462656565
  47. statement error duplicate key value
  48. INSERT INTO u VALUES ('63616665-6630-3064-6465-616462656566')
  49. statement error duplicate key value
  50. INSERT INTO u VALUES ('63616665-6630-3064-6465-616462656569', '63616665-6630-3064-6465-616462656565')
  51. statement error UUID must be exactly 16 bytes long, got 15 bytes
  52. INSERT INTO u VALUES (b'cafef00ddeadbee')
  53. statement error UUID must be exactly 16 bytes long, got 17 bytes
  54. INSERT INTO u VALUES (b'cafef00ddeadbeefs')
  55. statement error uuid: incorrect UUID length
  56. INSERT INTO u VALUES ('63616665-6630-3064-6465-61646265656')
  57. statement error uuid: incorrect UUID length
  58. INSERT INTO u VALUES ('63616665-6630-3064-6465-6164626565620')
  59. statement error unsupported comparison operator: <uuid> = <bytes>
  60. SELECT token FROM u WHERE token=b'cafef00ddeadbeef'::bytes
  61. statement error unsupported comparison operator: <uuid> = <string>
  62. SELECT token FROM u WHERE token='63616665-6630-3064-6465-616462656562'::string
  63. statement ok
  64. SELECT token FROM u WHERE token='63616665-6630-3064-6465-616462656562'::uuid
  65. query T
  66. SELECT token FROM u WHERE token='urn:uuid:63616665-6630-3064-6465-616462656562'
  67. ----
  68. 63616665-6630-3064-6465-616462656562
  69. query T
  70. SELECT token FROM u WHERE token=b'cafef00ddeadbeef'
  71. ----
  72. 63616665-6630-3064-6465-616462656566
  73. query T
  74. SELECT token2 FROM u WHERE token2='63616665-6630-3064-6465-616462656563'
  75. ----
  76. 63616665-6630-3064-6465-616462656563
  77. query T
  78. SELECT token FROM u WHERE token IN ('63616665-6630-3064-6465-616462656562', '63616665-6630-3064-6465-616462656564') ORDER BY token
  79. ----
  80. 63616665-6630-3064-6465-616462656562
  81. 63616665-6630-3064-6465-616462656564
  82. statement ok
  83. INSERT INTO u VALUES ('63616665-6630-3064-6465-616462656567'::uuid)
  84. statement ok
  85. INSERT INTO u VALUES ('urn:uuid:63616665-6630-3064-6465-616462656568'::uuid)
  86. statement ok
  87. INSERT INTO u VALUES (uuid_v4()::uuid)
  88. statement error value type bytes doesn't match type uuid
  89. INSERT INTO u VALUES ('cafef00ddeadbeef'::bytes)
  90. statement error value type text doesn't match type uuid
  91. INSERT INTO u VALUES ('63616665-6630-3064-6465-616462656562'::string)
  92. statement error value type bytes doesn't match type uuid
  93. INSERT INTO u VALUES (uuid_v4())
  94. query T
  95. SELECT token::uuid FROM u WHERE token=b'cafef00ddeadbeef'
  96. ----
  97. 63616665-6630-3064-6465-616462656566
  98. query T
  99. SELECT token::string FROM u WHERE token=b'cafef00ddeadbeef'
  100. ----
  101. 63616665-6630-3064-6465-616462656566
  102. query T
  103. SELECT token::bytes FROM u WHERE token=b'cafef00ddeadbeef'
  104. ----
  105. cafef00ddeadbeef
  106. statement error invalid cast: uuid -> int
  107. SELECT token::int FROM u
  108. query T
  109. SELECT ('63616665-6630-3064-6465-616462656562' COLLATE en)::uuid
  110. ----
  111. 63616665-6630-3064-6465-616462656562