two-source-schemas.td 2.3 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. > CREATE TABLE t1 FROM SOURCE mz_source (REFERENCE schema1.t1);
  40. ! CREATE TABLE t1 FROM SOURCE mz_source (REFERENCE schema2.t1);
  41. contains:catalog item 't1' already exists
  42. > DROP TABLE t1;
  43. ! CREATE TABLE t1 FROM SOURCE mz_source (REFERENCE t1);
  44. contains:reference t1 is ambiguous, consider specifying an additional layer of qualification
  45. > CREATE TABLE t1 FROM SOURCE mz_source (REFERENCE schema1.t1);
  46. > SELECT * FROM t1;
  47. 1
  48. 1
  49. > DROP SOURCE mz_source CASCADE;
  50. > CREATE SOURCE mz_source FROM POSTGRES CONNECTION pg (PUBLICATION 'mz_source');
  51. > CREATE TABLE t1_1 FROM SOURCE mz_source (REFERENCE schema1.t1);
  52. > CREATE TABLE t1_2 FROM SOURCE mz_source (REFERENCE schema2.t1);
  53. > SELECT * FROM t1_1;
  54. 1
  55. 1
  56. > SELECT * FROM t1_2;
  57. 2
  58. 2
  59. $ postgres-execute connection=postgres://postgres:postgres@postgres
  60. DROP SCHEMA schema1 CASCADE;
  61. DROP SCHEMA schema2 CASCADE;
  62. > DROP SOURCE mz_source CASCADE;