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

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

 



"Campbell, Lance" <lance@xxxxxxxxxxxx> 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

-- 
Sent via pgsql-admin mailing list (pgsql-admin@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux