Move all elements toward another schema? - Mailing list pgsql-general

From celati Laurent
Subject Move all elements toward another schema?
Date
Msg-id CAHByMH2pib5H1nwnkJJr3zSBhwwpk_15SQ8W5UaYQgYn+b3mUg@mail.gmail.com
Whole thread Raw
Responses Re: Move all elements toward another schema?  ("David G. Johnston" <david.g.johnston@gmail.com>)
Re: Move all elements toward another schema?  (Marcos Pegoraro <marcos@f10.com.br>)
List pgsql-general
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.

pgsql-general by date:

Previous
From: Ron
Date:
Subject: Re: Quit currently running query
Next
From: Tom Lane
Date:
Subject: Re: 13.x, stream replication and locale(?) issues