Re: How to change all owners on all objects in a schema

Поиск
Список
Период
Сортировка
От Kevin Grittner
Тема Re: How to change all owners on all objects in a schema
Дата
Msg-id 4E035E20020000250003EB41@gw.wicourts.gov
обсуждение исходный текст
Ответ на How to change all owners on all objects in a schema  ("Campbell, Lance" <lance@illinois.edu>)
Ответы Re: How to change all owners on all objects in a schema  ("Kevin Grittner" <Kevin.Grittner@wicourts.gov>)
Список pgsql-admin
"Campbell, Lance" <lance@illinois.edu> wrote:

> PostgreSQL: 9.0.x
>
> How do I change the ownership of all objects within a schema from
> X to Y?  The objects within each schema would be tables and
> sequences.

I would use DO statements.  What could be done as a one-liner to
handle the tables is shown below with line breaks for readability.

do $$
  declare stmt text;
  begin
    for stmt in
      select 'alter table oldschema.'
             || quote_ident(relname)
             || ' set schema newschema;'
        from pg_class
        where relkind = 'r'
          and relnamespace =
              (
                select oid from pg_catalog.pg_namespace
                  where nspname = 'oldschema'
              )
    loop
      raise notice '%', stmt;
    end loop;
  end;
$$;

Similar for sequences, only ALTER SEQUENCE and relkind = 'S'.

-Kevin

В списке pgsql-admin по дате отправления:

Предыдущее
От: Kasia Tuszynska
Дата:
Сообщение: C collation and Template 1
Следующее
От: "Kevin Grittner"
Дата:
Сообщение: Re: How to change all owners on all objects in a schema