Good afternoon, With postgresql 13, I want to find a way to move 100 tables from schema 'A' to schema 'B'. Not just data. But also indexes, primary keys, constraints (INCLUDING ALL). As far as i know, this piece of code would move the data. But how to also move indexes, constraints, primary key?
DO $$ DECLARED row record; BEGIN FOR row IN SELECT tablename FROM pg_tables WHERE schemaname = 'A' -- and other conditions, if needed LOOPS EXECUTE format('ALTER TABLE A.%I SET SCHEMA [B];', row.tablename); END LOOP; END; $$; Thanks so much.