types-character.td 2.0 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. #
  10. # Test the various character data types
  11. #
  12. > CREATE SECRET pgpass AS 'postgres'
  13. > CREATE CONNECTION pg TO POSTGRES (
  14. HOST postgres,
  15. DATABASE postgres,
  16. USER postgres,
  17. PASSWORD SECRET pgpass
  18. )
  19. # Insert data pre-snapshot
  20. $ postgres-execute connection=postgres://postgres:postgres@postgres
  21. ALTER USER postgres WITH replication;
  22. DROP SCHEMA IF EXISTS public CASCADE;
  23. DROP PUBLICATION IF EXISTS mz_source;
  24. CREATE SCHEMA public;
  25. CREATE TABLE t1 (f1 VARCHAR(10), f2 CHAR(10), f3 TEXT, f4 varchar);
  26. ALTER TABLE t1 REPLICA IDENTITY FULL;
  27. INSERT INTO t1 VALUES ('abc', 'abc', 'abc', 'abc');
  28. INSERT INTO t1 VALUES ('abc ', 'abc ', 'abc ', 'abc ');
  29. CREATE PUBLICATION mz_source FOR ALL TABLES;
  30. > CREATE SOURCE mz_source FROM POSTGRES CONNECTION pg (PUBLICATION 'mz_source');
  31. > CREATE TABLE t1 FROM SOURCE mz_source (REFERENCE t1);
  32. > SELECT COUNT(*) > 0 FROM t1;
  33. true
  34. # Insert the same data post-snapshot
  35. $ postgres-execute connection=postgres://postgres:postgres@postgres
  36. INSERT INTO t1 SELECT * FROM t1;
  37. > SELECT pg_typeof(f1), pg_typeof(f2), pg_typeof(f3), pg_typeof(f4) FROM t1 LIMIT 1;
  38. "character varying" "character" "text" "character varying"
  39. > SELECT * FROM t1;
  40. "abc" "abc " "abc" "abc"
  41. "abc" "abc " "abc" "abc"
  42. "abc " "abc " "abc " "abc "
  43. "abc " "abc " "abc " "abc "
  44. $ postgres-execute connection=postgres://postgres:postgres@postgres
  45. UPDATE t1 SET f1 = 'klm', f2 = 'klm', f3 = 'klm', f4 = 'klm' WHERE f1 = 'abc';
  46. UPDATE t1 SET f1 = 'xyz ', f2 = 'xyz ', f3 = 'xyz ', f4 = 'xyz ' WHERE f1 = 'abc ';
  47. > SELECT * FROM t1;
  48. "klm" "klm " "klm" "klm"
  49. "klm" "klm " "klm" "klm"
  50. "xyz " "xyz " "xyz " "xyz "
  51. "xyz " "xyz " "xyz " "xyz "