scale.slt 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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/scale
  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 test (
  24. t CHAR(4),
  25. UNIQUE INDEX a (t)
  26. )
  27. statement ok
  28. INSERT INTO test VALUES ('a')
  29. statement ok
  30. INSERT INTO test VALUES ('ab')
  31. statement ok
  32. INSERT INTO test VALUES ('abcd')
  33. statement error value too long for type CHAR\(4\) \(column "t"\)
  34. INSERT INTO test VALUES ('abcdef')
  35. statement ok
  36. INSERT INTO test VALUES ('áááá')
  37. statement error value too long
  38. INSERT INTO test VALUES ('ááááß')
  39. statement ok
  40. UPDATE test SET t = 'b' WHERE t = 'abcde'
  41. statement error value too long
  42. UPDATE test SET t = 'cdefg' WHERE t = 'ab'
  43. statement ok
  44. CREATE TABLE tb (
  45. b BIT(3),
  46. UNIQUE INDEX a (b)
  47. )
  48. statement ok
  49. INSERT INTO tb VALUES (B'001')
  50. statement ok
  51. INSERT INTO tb VALUES (B'011')
  52. statement ok
  53. INSERT INTO tb VALUES (B'111')
  54. statement error bit string length 4 does not match type BIT\(3\)
  55. INSERT INTO tb VALUES (B'1111')
  56. statement ok
  57. UPDATE tb SET b = B'010' WHERE b = B'111'
  58. statement error bit string length 5 does not match type BIT\(3\)
  59. UPDATE tb SET b = B'10000' WHERE b = B'010'
  60. statement ok
  61. CREATE TABLE tc (
  62. b INT2,
  63. UNIQUE INDEX a (b)
  64. )
  65. statement ok
  66. INSERT INTO tc VALUES (50)
  67. statement ok
  68. INSERT INTO tc VALUES (-32768)
  69. statement ok
  70. INSERT INTO tc VALUES (32767)
  71. # Note that neither of these value are INT2, but we only check
  72. # on insert and update, not mathematical operations
  73. statement ok
  74. INSERT INTO tc VALUES (60000-59999)
  75. statement error integer out of range for type int2 \(column "b"\)
  76. INSERT INTO tc VALUES (-32769)
  77. statement error integer out of range for type int2 \(column "b"\)
  78. INSERT INTO tc VALUES (32768)
  79. statement ok
  80. UPDATE tc SET b = 80 WHERE b = 50
  81. statement error integer out of range for type int2 \(column "b"\)
  82. UPDATE tc SET b = 32768 WHERE b = 32767
  83. statement ok
  84. CREATE TABLE tc1 (
  85. b INT4,
  86. UNIQUE INDEX a (b)
  87. )
  88. statement ok
  89. INSERT INTO tc1 VALUES (50)
  90. statement ok
  91. INSERT INTO tc1 VALUES (-2147483648)
  92. statement ok
  93. INSERT INTO tc1 VALUES (2147483647)
  94. statement error integer out of range for type int4 \(column "b"\)
  95. INSERT INTO tc1 VALUES (-2147483649)
  96. statement error integer out of range for type int4 \(column "b"\)
  97. INSERT INTO tc1 VALUES (2147483648)
  98. statement ok
  99. UPDATE tc1 SET b = 80 WHERE b = 50
  100. statement error integer out of range for type int4 \(column "b"\)
  101. UPDATE tc1 SET b = 2147483648 WHERE b = 2147483647
  102. statement ok
  103. CREATE TABLE td (
  104. d DECIMAL(3, 2),
  105. UNIQUE INDEX b (d)
  106. )
  107. statement ok
  108. INSERT INTO td VALUES (DECIMAL '3.1')
  109. statement ok
  110. INSERT INTO td VALUES (DECIMAL '3.14')
  111. statement error duplicate
  112. INSERT INTO td VALUES (DECIMAL '3.1415')
  113. statement error type DECIMAL\(3,2\) \(column "d"\): value with precision 3, scale 2 must round to an absolute value less than 10\^1
  114. INSERT INTO td VALUES (DECIMAL '13.1415')
  115. query R rowsort
  116. SELECT d FROM td
  117. ----
  118. 3.10
  119. 3.14
  120. statement error must round
  121. UPDATE td SET d = DECIMAL '101.414' WHERE d = DECIMAL '3.14'
  122. statement ok
  123. UPDATE td SET d = DECIMAL '1.414' WHERE d = DECIMAL '3.14'
  124. statement error duplicate
  125. UPDATE td SET d = DECIMAL '1.41' WHERE d = DECIMAL '3.1'
  126. query R rowsort
  127. SELECT d FROM td
  128. ----
  129. 3.10
  130. 1.41
  131. statement ok
  132. CREATE TABLE td2 (x DECIMAL(3), y DECIMAL)
  133. statement ok
  134. INSERT INTO td2 VALUES (DECIMAL '123.1415', DECIMAL '123.1415')
  135. query RR
  136. select x, y FROM td2
  137. ----
  138. 123 123.1415
  139. # Ensure decimal columns greater than 16 precision are supported.
  140. statement ok
  141. CREATE TABLE td3 (a decimal, b decimal(3, 1), c decimal(20, 10))
  142. statement ok
  143. INSERT INTO td3 VALUES (123456789012.123456789012, 12.3, 1234567890.1234567890)
  144. query RRR
  145. select * from td3
  146. ----
  147. 123456789012.123456789012 12.3 1234567890.1234567890
  148. statement error must round
  149. INSERT INTO td3 (c) VALUES (12345678901)