two-source-schemas.td 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 that identically-named tables in two source schemas can be
  11. # successfully disambiguated and replicated
  12. #
  13. > CREATE SECRET pgpass AS 'postgres'
  14. > CREATE CONNECTION pg TO POSTGRES (
  15. HOST postgres,
  16. DATABASE postgres,
  17. USER postgres,
  18. PASSWORD SECRET pgpass
  19. )
  20. $ postgres-execute connection=postgres://postgres:postgres@postgres
  21. ALTER USER postgres WITH replication;
  22. DROP PUBLICATION IF EXISTS mz_source;
  23. DROP SCHEMA IF EXISTS schema1 CASCADE;
  24. CREATE SCHEMA schema1;
  25. CREATE TABLE schema1.t1 (f1 INTEGER);
  26. ALTER TABLE schema1.t1 REPLICA IDENTITY FULL;
  27. INSERT INTO schema1.t1 VALUES (1);
  28. DROP SCHEMA IF EXISTS schema2 CASCADE;
  29. CREATE SCHEMA schema2;
  30. CREATE TABLE schema2.t1 (f1 INTEGER);
  31. ALTER TABLE schema2.t1 REPLICA IDENTITY FULL;
  32. INSERT INTO schema2.t1 VALUES (2);
  33. CREATE PUBLICATION mz_source FOR ALL TABLES;
  34. $ postgres-execute connection=postgres://postgres:postgres@postgres
  35. INSERT INTO schema1.t1 SELECT * FROM schema1.t1;
  36. INSERT INTO schema2.t1 SELECT * FROM schema2.t1;
  37. ! CREATE SOURCE mz_source
  38. FROM POSTGRES CONNECTION pg (PUBLICATION 'mz_source')
  39. FOR ALL TABLES;
  40. contains:multiple subsources would be named t1
  41. ! CREATE SOURCE mz_source
  42. FROM POSTGRES CONNECTION pg (PUBLICATION 'mz_source')
  43. FOR TABLES (t1);
  44. contains:reference t1 is ambiguous, consider specifying an additional layer of qualification
  45. > CREATE SOURCE mz_source
  46. FROM POSTGRES CONNECTION pg (PUBLICATION 'mz_source')
  47. FOR TABLES (schema1.t1);
  48. > SELECT * FROM t1;
  49. 1
  50. 1
  51. > DROP SOURCE mz_source CASCADE;
  52. > CREATE SOURCE mz_source
  53. FROM POSTGRES CONNECTION pg (PUBLICATION 'mz_source')
  54. FOR TABLES (schema1.t1 AS t1_1, schema2.t1 AS t1_2);
  55. > SELECT * FROM t1_1;
  56. 1
  57. 1
  58. > SELECT * FROM t1_2;
  59. 2
  60. 2
  61. $ postgres-execute connection=postgres://postgres:postgres@postgres
  62. DROP SCHEMA schema1 CASCADE;
  63. DROP SCHEMA schema2 CASCADE;
  64. > DROP SOURCE mz_source CASCADE;