types-enum.td 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. # TODO: database-issues#7719 (enum unsupported)
  27. ! CREATE SOURCE mz_source
  28. FROM MYSQL CONNECTION mysql_conn
  29. FOR ALL TABLES;
  30. contains:referenced tables use unsupported types
  31. > CREATE SOURCE mz_source
  32. FROM MYSQL CONNECTION mysql_conn (
  33. TEXT COLUMNS (public.enum_type.f1)
  34. )
  35. FOR ALL TABLES;
  36. > SELECT * FROM enum_type;
  37. val1 val1
  38. val2 val2
  39. # Add an additional enum value type
  40. $ mysql-execute name=mysql
  41. ALTER TABLE enum_type CHANGE f1 f1 ENUM ('val1', 'val2', 'val3');
  42. INSERT INTO enum_type VALUES ('val1', 'val1');
  43. > SELECT * FROM enum_type;
  44. val1 val1
  45. val2 val2
  46. val1 val1
  47. $ mysql-execute name=mysql
  48. INSERT INTO enum_type VALUES ('val3', 'val3');
  49. ! SELECT * FROM enum_type;
  50. contains:received invalid enum value: 3 for column f1
  51. $ mysql-execute name=mysql
  52. DELETE FROM enum_type WHERE f1 = 'val3';
  53. > SELECT * FROM enum_type;
  54. val1 val1
  55. val2 val2
  56. val1 val1
  57. # Add an additional enum value type and change the ordering
  58. $ mysql-execute name=mysql
  59. ALTER TABLE enum_type CHANGE f1 f1 ENUM ('val2', 'val1', 'val3', 'val4');
  60. INSERT INTO enum_type VALUES ('val1', 'val1');
  61. ! SELECT * FROM enum_type;
  62. contains:incompatible schema change: column f1 in table enum_type has been altered