extract.slt 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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 evaluation test suite in CockroachDB.
  12. # The original file was retrieved on October 7, 2019 from:
  13. #
  14. # https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/sem/tree/testdata/eval/extract
  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. # Extract from dates.
  20. skipif postgresql # literal coercion for dates is not supported
  21. query I
  22. SELECT extract(year FROM '2010-09-28')
  23. ----
  24. 2010
  25. query I
  26. SELECT extract(year FROM DATE '2010-09-28')
  27. ----
  28. 2010
  29. query I
  30. SELECT extract(month FROM DATE '2010-09-28')
  31. ----
  32. 9
  33. query I
  34. SELECT extract(day FROM DATE '2010-09-28')
  35. ----
  36. 28
  37. skipif postgresql # dayofyear is not supported
  38. query I
  39. SELECT extract(dayofyear FROM DATE '2010-09-28')
  40. ----
  41. 271
  42. skipif postgresql # week is not supported
  43. query I
  44. SELECT extract(week FROM DATE '2010-01-14')
  45. ----
  46. 2
  47. skipif postgresql # dayofweek is not supported
  48. query I
  49. SELECT extract(dayofweek FROM DATE '2010-09-28')
  50. ----
  51. 2
  52. skipif postgresql # quarter is not supported
  53. query I
  54. SELECT extract(quarter FROM DATE '2010-09-28')
  55. ----
  56. 3
  57. # Extract from times. These don't currently work, because we don't support the
  58. # TIME data type, which is distinct from TIMESTAMP and DATE.
  59. skipif postgresql
  60. query I
  61. SELECT extract(hour FROM TIME '12:00:00')
  62. ----
  63. 12
  64. skipif postgresql
  65. query I
  66. SELECT extract(minute FROM TIME '12:30:00')
  67. ----
  68. 30
  69. skipif postgresql
  70. query I
  71. SELECT extract(second FROM TIME '12:00:30')
  72. ----
  73. 30
  74. skipif postgresql
  75. query I
  76. SELECT extract(millisecond FROM TIME '12:00:00.123456')
  77. ----
  78. 123
  79. skipif postgresql
  80. query I
  81. SELECT extract(microsecond FROM TIME '12:00:00.123456')
  82. ----
  83. 123456
  84. # Extract from timestamps.
  85. skipif postgresql # literal coercion for timestamps is not supported
  86. query I
  87. SELECT extract(year FROM '2010-09-28 12:13:14.1')
  88. ----
  89. 2010
  90. query I
  91. SELECT extract(year FROM TIMESTAMP '2010-09-28 12:13:14.1')
  92. ----
  93. 2010
  94. query I
  95. SELECT extract(month FROM TIMESTAMP '2010-09-28 12:13:14.1')
  96. ----
  97. 9
  98. query I
  99. SELECT extract(day FROM TIMESTAMP '2010-09-28 12:13:14.1')
  100. ----
  101. 28
  102. skipif postgresql # dayofyear is not supported
  103. query I
  104. SELECT extract(dayofyear FROM TIMESTAMP '2010-09-28 12:13:14.1')
  105. ----
  106. 271
  107. skipif postgresql # week is not supported
  108. query I
  109. SELECT extract(week FROM TIMESTAMP '2010-01-14 12:13:14.1')
  110. ----
  111. 2
  112. skipif postgresql # dayofweek is not supported
  113. query I
  114. SELECT extract(dayofweek FROM TIMESTAMP '2010-09-28 12:13:14.1')
  115. ----
  116. 2
  117. skipif postgresql # quarter is not supported
  118. query I
  119. SELECT extract(quarter FROM TIMESTAMP '2010-09-28 12:13:14.1')
  120. ----
  121. 3
  122. query I
  123. SELECT extract(hour FROM TIMESTAMP '2010-01-10 12:13:14.1')
  124. ----
  125. 12
  126. query I
  127. SELECT extract(minute FROM TIMESTAMP '2010-01-10 12:13:14.1')
  128. ----
  129. 13
  130. query R
  131. SELECT extract(second FROM TIMESTAMP '2010-01-10 12:13:14.1')
  132. ----
  133. 14.1
  134. skipif postgresql # millisecond is not supported
  135. query R
  136. SELECT extract(millisecond FROM TIMESTAMP '2010-01-10 12:13:14.123456')
  137. ----
  138. 14123.456
  139. skipif postgresql # microsecond is not supported
  140. query I
  141. SELECT extract(microsecond FROM TIMESTAMP '2010-01-10 12:13:14.123456')
  142. ----
  143. 123456
  144. query I
  145. SELECT extract(epoch FROM TIMESTAMP '2010-01-10 12:13:14.1')
  146. ----
  147. 1263125594
  148. # Extract from intervals.
  149. skipif postgresql # literal coercion for intervals is not supported
  150. query I
  151. SELECT extract(hour FROM '123m')
  152. ----
  153. 2
  154. query I
  155. SELECT extract(hour FROM INTERVAL '123' MINUTE)
  156. ----
  157. 2
  158. query I
  159. SELECT extract(minute FROM INTERVAL '23:10' MINUTE TO SECOND)
  160. ----
  161. 23
  162. query R
  163. SELECT extract(second FROM INTERVAL '10:20.30' MINUTE TO SECOND)
  164. ----
  165. 20.3
  166. skipif postgresql # millisecond is not supported
  167. query R
  168. SELECT extract(millisecond FROM INTERVAL '20.3040' SECOND)
  169. ----
  170. 20304
  171. query R
  172. SELECT extract(epoch FROM INTERVAL '10:20.30' MINUTE TO SECOND)
  173. ----
  174. 620.3