types-enum.td 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. $ set-sql-timeout duration=1s
  10. #
  11. # ENUM supported only as TEXT
  12. #
  13. > CREATE SECRET mysqlpass AS '${arg.mysql-root-password}'
  14. > CREATE CONNECTION mysql_conn TO MYSQL (
  15. HOST mysql,
  16. USER root,
  17. PASSWORD SECRET mysqlpass
  18. )
  19. $ mysql-connect name=mysql url=mysql://root@mysql password=${arg.mysql-root-password}
  20. $ mysql-execute name=mysql
  21. DROP DATABASE IF EXISTS public;
  22. CREATE DATABASE public;
  23. USE public;
  24. CREATE TABLE enum_type (f1 ENUM ('val1', 'val2'), f2 TEXT);
  25. INSERT INTO enum_type VALUES ('val1', 'val1'), ('val2', 'val2');
  26. > CREATE SOURCE mz_source FROM MYSQL CONNECTION mysql_conn;
  27. # TODO: database-issues#7719 (enum unsupported)
  28. ! CREATE TABLE enum_type FROM SOURCE mz_source (REFERENCE public.enum_type);
  29. contains:referenced tables use unsupported types
  30. > CREATE TABLE enum_type FROM SOURCE mz_source (REFERENCE public.enum_type) WITH (TEXT COLUMNS (f1));
  31. > SELECT * FROM enum_type;
  32. val1 val1
  33. val2 val2
  34. # Add an additional enum value type
  35. $ mysql-execute name=mysql
  36. ALTER TABLE enum_type CHANGE f1 f1 ENUM ('val1', 'val2', 'val3');
  37. INSERT INTO enum_type VALUES ('val1', 'val1');
  38. > SELECT * FROM enum_type;
  39. val1 val1
  40. val2 val2
  41. val1 val1
  42. $ mysql-execute name=mysql
  43. INSERT INTO enum_type VALUES ('val3', 'val3');
  44. ! SELECT * FROM enum_type;
  45. contains:received invalid enum value: 3 for column f1
  46. $ mysql-execute name=mysql
  47. DELETE FROM enum_type WHERE f1 = 'val3';
  48. > SELECT * FROM enum_type;
  49. val1 val1
  50. val2 val2
  51. val1 val1
  52. # Add an additional enum value type and change the ordering
  53. $ mysql-execute name=mysql
  54. ALTER TABLE enum_type CHANGE f1 f1 ENUM ('val2', 'val1', 'val3', 'val4');
  55. INSERT INTO enum_type VALUES ('val1', 'val1');
  56. ! SELECT * FROM enum_type;
  57. contains:incompatible schema change: column f1 in table enum_type has been altered