types-interval.td 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. # MySQL specifies that pg type INTERVAL is mapped to TIME in MySQL.
  10. #
  11. # Test the INTERVAL 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 TIME(6));
  26. INSERT INTO t1 VALUES (TIME '23:59:59')
  27. > CREATE SOURCE mz_source FROM MYSQL CONNECTION mysql_conn;
  28. > CREATE TABLE t1 FROM SOURCE mz_source (REFERENCE public.t1);
  29. > SELECT COUNT(*) > 0 FROM t1;
  30. true
  31. # Insert the same data post-snapshot
  32. $ mysql-execute name=mysql
  33. INSERT INTO t1 SELECT * FROM t1;
  34. > SELECT pg_typeof(f1) FROM t1 LIMIT 1;
  35. time
  36. > SELECT * FROM t1;
  37. "23:59:59"
  38. "23:59:59"
  39. # Now insert an out-of-bounds time value that should
  40. # put us into an error state
  41. $ mysql-execute name=mysql
  42. INSERT INTO t1 VALUES (TIME '838:59:59')
  43. ! SELECT * FROM t1;
  44. contains: error decoding value
  45. # Drop and recreate the source to confirm the decoding
  46. # error is also encountered in the snapshot phase
  47. > DROP SOURCE mz_source CASCADE;
  48. > CREATE SOURCE mz_source FROM MYSQL CONNECTION mysql_conn;
  49. > CREATE TABLE t1 FROM SOURCE mz_source (REFERENCE public.t1);
  50. ! SELECT * FROM t1;
  51. contains: error decoding value
  52. > DROP SOURCE mz_source CASCADE;