Move all elements toward another schema?

Поиск
Список
Период
Сортировка
От celati Laurent
Тема Move all elements toward another schema?
Дата
Msg-id CAHByMH2pib5H1nwnkJJr3zSBhwwpk_15SQ8W5UaYQgYn+b3mUg@mail.gmail.com
обсуждение исходный текст
Ответы 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>)
Список 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 по дате отправления:

Предыдущее
От: Ron
Дата:
Сообщение: Re: Quit currently running query
Следующее
От: Tom Lane
Дата:
Сообщение: Re: 13.x, stream replication and locale(?) issues