Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id ECEA2B5DC32 for ; Thu, 23 Jun 2011 17:39:29 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 95415-01 for ; Thu, 23 Jun 2011 20:39:23 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from gw.wicourts.gov (gwmta.wicourts.gov [165.219.244.99]) by mail.postgresql.org (Postfix) with ESMTP id CEB3EB5D91F for ; Thu, 23 Jun 2011 17:39:22 -0300 (ADT) Received: from Courts-MTA by gw.wicourts.gov with Novell_GroupWise; Thu, 23 Jun 2011 15:39:22 -0500 Message-Id: <4E035E20020000250003EB41@gw.wicourts.gov> X-Mailer: Novell GroupWise Internet Agent 8.0.1 Date: Thu, 23 Jun 2011 15:39:12 -0500 From: "Kevin Grittner" To: "Lance Campbell" , "pgsql-admin@postgresql.org" Subject: Re: How to change all owners on all objects in a schema References: In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201106/137 X-Sequence-Number: 37763 "Campbell, Lance" 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