cast.slt 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. query R
  10. SELECT 1.4::int
  11. ----
  12. 1
  13. query R
  14. SELECT 1.5::int
  15. ----
  16. 2
  17. query R
  18. SELECT 1.4::real::int
  19. ----
  20. 1
  21. query R
  22. SELECT 1.5::real::int
  23. ----
  24. 2
  25. query R
  26. SELECT 1.4::float::int
  27. ----
  28. 1
  29. query R
  30. SELECT 1.5::float::int
  31. ----
  32. 2
  33. query R
  34. SELECT 1.4::bigint
  35. ----
  36. 1
  37. query R
  38. SELECT 1.5::bigint
  39. ----
  40. 2
  41. query R
  42. SELECT 1.4::real::bigint
  43. ----
  44. 1
  45. query R
  46. SELECT 1.5::real::bigint
  47. ----
  48. 2
  49. query R
  50. SELECT 1.4::float::bigint
  51. ----
  52. 1
  53. query R
  54. SELECT 1.5::float::bigint
  55. ----
  56. 2
  57. # 🔬 Custom types
  58. # TODO(sploiselle): fix return type to indicate custom type
  59. statement ok
  60. CREATE TYPE int4_list AS LIST (ELEMENT TYPE = int4)
  61. statement ok
  62. CREATE TYPE int4_list_list AS LIST (ELEMENT TYPE = int4_list)
  63. statement ok
  64. CREATE TYPE int4_list_too AS LIST (ELEMENT TYPE = int4)
  65. statement ok
  66. CREATE TYPE int4_list_list_too AS LIST (ELEMENT TYPE = int4_list_too)
  67. query T
  68. SELECT pg_typeof('{1}'::int4 list::int4_list)
  69. ----
  70. int4_list
  71. query T
  72. SELECT pg_typeof('{1}'::int4_list::int4 list)
  73. ----
  74. integer list
  75. query T
  76. SELECT pg_typeof('{1}'::int4_list_list::int4_list_list_too)
  77. ----
  78. int4_list_list_too
  79. query T
  80. SELECT pg_typeof('{1}'::int4_list_list_too::int4_list_list)
  81. ----
  82. int4_list_list
  83. query TTT
  84. SELECT CAST('2020-01-01' AS date), CAST('2020-01-01'::timestamp as date), CAST('2020-01-01'::timestamptz as date)
  85. ----
  86. 2020-01-01
  87. 2020-01-01
  88. 2020-01-01
  89. # Postgres also supports `typename ( expression )` cast expressions with some limitations.
  90. # https://www.postgresql.org/docs/13/sql-expressions.html#SQL-SYNTAX-TYPE-CASTS
  91. # TODO: Support these more generally instead of just `date`.
  92. query TTT
  93. SELECT date('2020-01-01'), date('2020-01-01'::timestamp), date('2020-01-01'::timestamptz)
  94. ----
  95. 2020-01-01
  96. 2020-01-01
  97. 2020-01-01
  98. query error invalid input syntax for type date
  99. SELECT date('2000')
  100. query error db error: ERROR: function date\(unknown, unknown\) does not exist
  101. SELECT date('2000', 'a')
  102. query T
  103. SELECT CAST(5 + 3 AS text);
  104. ----
  105. 8
  106. query T
  107. SELECT (5 + 3)::text;
  108. ----
  109. 8
  110. query error db error: ERROR: operator does not exist: integer \+ text
  111. SELECT 5 + 3::text;