Search Postgresql Archives

Move all elements toward another schema?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux