types.td 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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. $ postgres-connect name=mz_system url=postgres://mz_system:materialize@${testdrive.materialize-internal-sql-addr}
  10. # Without EXTENDED, SHOW TYPES shouldn't have anything to return.
  11. > SHOW TYPES
  12. > SHOW TYPES
  13. > SHOW TYPES FROM pg_catalog
  14. name comment
  15. ------------------------------
  16. _aclitem ""
  17. _bool ""
  18. _bpchar ""
  19. _bytea ""
  20. _char ""
  21. _date ""
  22. _daterange ""
  23. _float4 ""
  24. _float8 ""
  25. _int2 ""
  26. _int2vector ""
  27. _int4 ""
  28. _int4range ""
  29. _int8 ""
  30. _int8range ""
  31. _interval ""
  32. _jsonb ""
  33. _name ""
  34. _numeric ""
  35. _numrange ""
  36. _oid ""
  37. _record ""
  38. _regclass ""
  39. _regproc ""
  40. _regtype ""
  41. _text ""
  42. _time ""
  43. _timestamp ""
  44. _timestamptz ""
  45. _tsrange ""
  46. _tstzrange ""
  47. _uuid ""
  48. _varchar ""
  49. aclitem ""
  50. any ""
  51. anyarray ""
  52. anycompatible ""
  53. anycompatiblearray ""
  54. anycompatiblenonarray ""
  55. anycompatiblerange ""
  56. anyelement ""
  57. anynonarray ""
  58. anyrange ""
  59. bool ""
  60. bpchar ""
  61. bytea ""
  62. char ""
  63. date ""
  64. daterange ""
  65. float4 ""
  66. float8 ""
  67. int2 ""
  68. int2vector ""
  69. int4 ""
  70. int4range ""
  71. int8 ""
  72. int8range ""
  73. internal ""
  74. interval ""
  75. jsonb ""
  76. name ""
  77. numeric ""
  78. numrange ""
  79. oid ""
  80. regclass ""
  81. regproc ""
  82. regtype ""
  83. record ""
  84. text ""
  85. time ""
  86. timestamp ""
  87. timestamptz ""
  88. tsrange ""
  89. tstzrange ""
  90. uuid ""
  91. varchar ""
  92. $ postgres-execute connection=mz_system
  93. ALTER SYSTEM SET max_tables = 10000
  94. # Support creating tables with catalog types and their aliases
  95. > CREATE TABLE bool_t (a bool);
  96. > CREATE TABLE boolean_t (a boolean);
  97. > CREATE TABLE bytea_t (a bytea);
  98. > CREATE TABLE bytes_t (a bytes);
  99. > CREATE TABLE date_t (a date);
  100. > CREATE TABLE float4_t (a float4);
  101. > CREATE TABLE real_t (a real);
  102. > CREATE TABLE float16_t (a float(16));
  103. > CREATE TABLE float8_t (a float8);
  104. > CREATE TABLE float_t (a float);
  105. > CREATE TABLE double_t (a double);
  106. > CREATE TABLE int2_t (a int2);
  107. > CREATE TABLE smallint_t (a smallint);
  108. > CREATE TABLE int4_t (a int4);
  109. > CREATE TABLE int_t (a int);
  110. > CREATE TABLE integer_t (a integer);
  111. > CREATE TABLE int8_t (a int8);
  112. > CREATE TABLE bigint_t (a bigint);
  113. > CREATE TABLE uint2_t (a uint2);
  114. > CREATE TABLE uint4_t (a uint4);
  115. > CREATE TABLE uint8_t (a uint8);
  116. > CREATE TABLE interval_t (a interval);
  117. > CREATE TABLE jsonb_t (a jsonb);
  118. > CREATE TABLE json_t (a json);
  119. > CREATE TABLE numeric_t (a numeric);
  120. > CREATE TABLE decimal_t (a decimal);
  121. > CREATE TABLE dec_t (a dec);
  122. > CREATE TABLE oid_t (a oid);
  123. > CREATE TABLE regclass_t (a regclass);
  124. > CREATE TABLE text_t (a text);
  125. > CREATE TABLE char_t (a char(100));
  126. > CREATE TABLE bpchar_t (a bpchar(100));
  127. > CREATE TABLE varchar_t (a varchar(100));
  128. > CREATE TABLE time_t (a time);
  129. > CREATE TABLE timestamp_t (a timestamp);
  130. > CREATE TABLE timestamptz_t (a timestamptz);
  131. > CREATE TABLE uuid_t (a uuid);
  132. # User-defined types
  133. > CREATE TYPE int_list_c AS LIST (ELEMENT TYPE = int4);
  134. > CREATE TYPE int_map_c AS MAP (KEY TYPE = text, VALUE TYPE = int4);
  135. > CREATE TYPE int_record_c AS (i1 int, i2 int, i3 int);
  136. # User-defined types can use other user-defined types
  137. > CREATE TYPE int_list_list_c AS LIST (ELEMENT TYPE = int_list_c);
  138. > CREATE TYPE int_record_record_c AS (j1 int, j2 int_record_c);
  139. > SHOW TYPES
  140. name comment
  141. ----------------------------
  142. int_list_c ""
  143. int_map_c ""
  144. int_list_list_c ""
  145. int_record_c ""
  146. int_record_record_c ""
  147. # Allow creating tables using custom types
  148. > CREATE TABLE custom_types (a int_list_c, b int_map_c);
  149. > INSERT INTO custom_types VALUES (LIST[1], '{a=>1}'::int_map_c);
  150. > CREATE TYPE int_array_list AS LIST (ELEMENT TYPE = _int4);
  151. > CREATE TABLE custom_types_2 (a int_array_list);
  152. > INSERT INTO custom_types_2 VALUES (LIST[ARRAY[1]]);
  153. > CREATE TABLE custom_types_3 (a int_record_c, b int_record_record_c);
  154. > INSERT INTO custom_types_3 VALUES (ROW(9, 8, 7), ROW(6, ROW(5, 4, 3)));
  155. # Custom types are namespaced objects
  156. > CREATE SCHEMA other;
  157. > CREATE TYPE other.other_int_list_c AS LIST (ELEMENT TYPE = int4);
  158. > CREATE TYPE other.other_int_map_c AS MAP (KEY TYPE = text, VALUE TYPE = int4);
  159. > CREATE TYPE other.other_record_c AS (a int, b text);
  160. > SHOW TYPES FROM other;
  161. name comment
  162. -------------------------
  163. other_int_list_c ""
  164. other_int_map_c ""
  165. other_record_c ""
  166. > CREATE TABLE custom_types_4 (a other.other_int_list_c, b other.other_int_map_c);
  167. > CREATE TYPE int_list_map AS MAP (KEY TYPE = text, VALUE TYPE = other.other_int_list_c)
  168. # Array element types
  169. > CREATE TYPE bool_array_list_c AS LIST (ELEMENT TYPE = _bool);
  170. > CREATE TABLE bool_array_list_t (a bool_array_list_c);
  171. > INSERT INTO bool_array_list_t VALUES (LIST[ARRAY[true]]);
  172. > CREATE TYPE int8_array_list_c AS LIST (ELEMENT TYPE = _int8);
  173. > CREATE TABLE int8_array_list_t (a int8_array_list_c);
  174. > INSERT INTO int8_array_list_t VALUES (LIST[ARRAY[1::int8,2::int8]]);
  175. > CREATE TYPE int4_array_list_c AS LIST (ELEMENT TYPE = _int4);
  176. > CREATE TABLE int4_array_list_t (a int4_array_list_c);
  177. > INSERT INTO int4_array_list_t VALUES (LIST[ARRAY[1,2]]);
  178. > CREATE TYPE text_array_list_c AS LIST (ELEMENT TYPE = _text);
  179. > CREATE TABLE text_array_list_t (a text_array_list_c);
  180. > INSERT INTO text_array_list_t VALUES (LIST[ARRAY['a','b']]);
  181. > CREATE TYPE varchar_array_list_c AS LIST (ELEMENT TYPE = _varchar);
  182. > CREATE TABLE varchar_array_list_t (a varchar_array_list_c);
  183. > INSERT INTO varchar_array_list_t VALUES (LIST[ARRAY['a'::varchar,'b'::varchar]]);
  184. # Enable this when closing database-issues#2360
  185. # > CREATE TYPE char_array_list_c AS LIST (ELEMENT TYPE = _char);
  186. # > CREATE TABLE char_array_list_t (a char_array_list_c);
  187. # > INSERT INTO char_array_list_t VALUES (LIST[ARRAY['a'::char,'b'::char]]);
  188. > CREATE TYPE float4_array_list_c AS LIST (ELEMENT TYPE = _float4);
  189. > CREATE TABLE float4_array_list_t (a float4_array_list_c);
  190. > INSERT INTO float4_array_list_t VALUES (LIST[ARRAY[1.2::float4,2.3::float4]]);
  191. > CREATE TYPE float8_array_list_c AS LIST (ELEMENT TYPE = _float8);
  192. > CREATE TABLE float8_array_list_t (a float8_array_list_c);
  193. > INSERT INTO float8_array_list_t VALUES (LIST[ARRAY[1.2::float8,2.3::float8]]);
  194. > CREATE TYPE date_array_list_c AS LIST (ELEMENT TYPE = _date);
  195. > CREATE TABLE date_array_list_t (a date_array_list_c);
  196. > INSERT INTO date_array_list_t VALUES (LIST[ARRAY['2001-01-01'::date]]);
  197. > CREATE TYPE time_array_list_c AS LIST (ELEMENT TYPE = _time);
  198. > CREATE TABLE time_array_list_t (a time_array_list_c);
  199. > INSERT INTO time_array_list_t VALUES (LIST[ARRAY['12:34:56'::time]]);
  200. > CREATE TYPE timestamp_array_list_c AS LIST (ELEMENT TYPE = _timestamp);
  201. > CREATE TABLE timestamp_array_list_t (a timestamp_array_list_c);
  202. > INSERT INTO timestamp_array_list_t VALUES (LIST[ARRAY['2001-01-01 12:34:56'::timestamp]]);
  203. > CREATE TYPE timestamptz_array_list_c AS LIST (ELEMENT TYPE = _timestamptz);
  204. > CREATE TABLE timestamptz_array_list_t (a timestamptz_array_list_c);
  205. > INSERT INTO timestamptz_array_list_t VALUES (LIST[ARRAY['2001-01-01 12:34:56'::timestamptz]]);
  206. > CREATE TYPE interval_array_list_c AS LIST (ELEMENT TYPE = _interval);
  207. > CREATE TABLE interval_array_list_t (a interval_array_list_c);
  208. > INSERT INTO interval_array_list_t VALUES (LIST[ARRAY['1y 2d 3h 4m'::interval]]);
  209. # > CREATE TYPE numeric_array_list_c AS LIST (ELEMENT TYPE = _numeric);
  210. # > CREATE TABLE numeric_array_list_t (a numeric_array_list_c);
  211. # > INSERT INTO numeric_array_list_t VALUES (LIST[ARRAY[1.23, 2.34]]);
  212. > CREATE TYPE jsonb_array_list_c AS LIST (ELEMENT TYPE = _jsonb);
  213. > CREATE TABLE jsonb_array_list_t (a jsonb_array_list_c);
  214. > INSERT INTO jsonb_array_list_t VALUES (LIST[ARRAY['{"1":2}'::jsonb]]);
  215. # Test pg_type_is_visible.
  216. > SELECT PG_TYPE_IS_VISIBLE('bool'::REGTYPE::OID);
  217. pg_type_is_visible
  218. --------------------
  219. true
  220. > CREATE SCHEMA hidden_schema;
  221. > CREATE TYPE hidden_schema.my_hidden_type AS LIST (ELEMENT TYPE = int4);
  222. > CREATE TYPE my_type AS LIST (ELEMENT TYPE = int4);
  223. > SELECT PG_TYPE_IS_VISIBLE(oid::REGTYPE) FROM mz_catalog.mz_types WHERE name='my_hidden_type';
  224. pg_type_is_visible
  225. --------------------
  226. false
  227. > SELECT PG_TYPE_IS_VISIBLE(oid::REGTYPE) FROM mz_catalog.mz_types WHERE name='my_type';
  228. pg_type_is_visible
  229. --------------------
  230. true
  231. # Ensure we don't allow unknown options
  232. ! CREATE TYPE whatever AS LIST (ELEMENT TYPE = int4, gus=int4);
  233. contains:Expected ELEMENT, found identifier
  234. $ postgres-execute connection=mz_system
  235. ALTER SYSTEM RESET ALL