types-boolean.td 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. # Test the BOOLEAN data type
  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. # Insert data pre-snapshot
  25. CREATE TABLE t1 (f1 BOOLEAN);
  26. INSERT INTO t1 VALUES (true), (false);
  27. # default values
  28. CREATE TABLE t2 (f1 INT, f2 BOOLEAN DEFAULT true, f3 BOOLEAN DEFAULT false, f4 BOOLEAN);
  29. INSERT INTO t2 VALUES (1, NULL, NULL, NULL);
  30. INSERT INTO t2 VALUES (2, false, false, false);
  31. INSERT INTO t2 (f1) VALUES (3);
  32. > CREATE SOURCE mz_source FROM MYSQL CONNECTION mysql_conn;
  33. > CREATE TABLE t1 FROM SOURCE mz_source (REFERENCE public.t1);
  34. > CREATE TABLE t2 FROM SOURCE mz_source (REFERENCE public.t2);
  35. > SELECT COUNT(*) > 0 FROM t1;
  36. true
  37. # Insert the same data post-snapshot
  38. $ mysql-execute name=mysql
  39. INSERT INTO t1 SELECT * FROM t1;
  40. # MySQL does not have a proper boolean type
  41. > SELECT pg_typeof(f1) FROM t1 LIMIT 1;
  42. smallint
  43. > SELECT * FROM t1;
  44. 1
  45. 0
  46. 1
  47. 0
  48. > SELECT * FROM t2;
  49. 1 <null> <null> <null>
  50. 2 0 0 0
  51. 3 1 0 <null>