Skip to content

Instantly share code, notes, and snippets.

@develost
Last active August 29, 2015 14:22
Show Gist options
  • Save develost/0be159559e5e0667ba44 to your computer and use it in GitHub Desktop.
Save develost/0be159559e5e0667ba44 to your computer and use it in GitHub Desktop.
Bulk change owner tables in multiple schema postgres
---------------------------------------------------------------------------------
--- Bulk alter table owner for all tables in multiple schema
--- to be run into pgAdmin "Execute pgScript"
---------------------------------------------------------------------------------
--- hint: replace MY_USER with your actual user
SET @elements = select schemaname, tablename from pg_tables where schemaname in ('public','test','whatever');
SET @i = 0;
WHILE @i < LINES(@elements)
BEGIN
SET @T = @elements[@i][0] + '.' + @elements[@i][1];
ALTER TABLE @T OWNER TO MY_USER;
SET @i = @i +1;
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment