truncate-table.td 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 TRUNCATE -- source will error out
  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. $ postgres-execute connection=postgres://postgres:postgres@postgres
  20. ALTER USER postgres WITH replication;
  21. DROP SCHEMA IF EXISTS public CASCADE;
  22. DROP PUBLICATION IF EXISTS mz_source;
  23. CREATE SCHEMA public;
  24. CREATE TABLE t1 (f1 INTEGER);
  25. ALTER TABLE t1 REPLICA IDENTITY FULL;
  26. INSERT INTO t1 VALUES (1);
  27. CREATE PUBLICATION mz_source FOR ALL TABLES;
  28. > CREATE SOURCE mz_source FROM POSTGRES CONNECTION pg (PUBLICATION 'mz_source');
  29. > CREATE TABLE t1 FROM SOURCE mz_source (REFERENCE t1);
  30. > SELECT * FROM t1;
  31. 1
  32. $ postgres-execute connection=postgres://postgres:postgres@postgres
  33. TRUNCATE TABLE t1;
  34. # Note: truncating the upstream table will not corrupt the source in Materialize
  35. # for Postgres version 10. For all versions > 10, users will see the following error
  36. # "source table got truncated."
  37. #
  38. # See the Postgres docs for more information:
  39. # https://www.postgresql.org/docs/10/logical-replication-restrictions.html
  40. ! SELECT * FROM t1;
  41. contains:table was truncated