invisible-columns.td 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. # Invisible columns
  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. SET sql_generate_invisible_primary_key=ON;
  25. CREATE TABLE t1 (f1 INT, f2 INT INVISIBLE, f3 DATE INVISIBLE, f4 INT INVISIBLE);
  26. INSERT INTO t1 (f1, f2, f3, f4) VALUES (10, 20, '2025-01-28', 6);
  27. INSERT INTO t1 VALUES (11);
  28. > CREATE SOURCE mz_source FROM MYSQL CONNECTION mysql_conn;
  29. > CREATE TABLE t1 FROM SOURCE mz_source (REFERENCE public.t1) WITH (TEXT COLUMNS (f3), EXCLUDE COLUMNS (f4));
  30. > SELECT * FROM t1;
  31. 1 10 20 "2025-01-28"
  32. 2 11 <null> <null>
  33. $ mysql-execute name=mysql
  34. ALTER TABLE t1 ALTER COLUMN f2 SET VISIBLE;
  35. INSERT INTO t1 (f1, f2, f3, f4) VALUES (111, 222, '2025-01-29', 6);
  36. INSERT INTO t1 (f1, f2) VALUES (1111, 2222);
  37. > SELECT * from t1;
  38. 1 10 20 "2025-01-28"
  39. 2 11 <null> <null>
  40. 3 111 222 "2025-01-29"
  41. 4 1111 2222 <null>
  42. $ mysql-execute name=mysql
  43. ALTER TABLE t1 DROP COLUMN f2;
  44. ! SELECT * FROM t1;
  45. contains:incompatible schema change