Skip to content

Instantly share code, notes, and snippets.

@alexander-arce
Created April 2, 2015 19:50
Show Gist options
  • Select an option

  • Save alexander-arce/2db0eed4968a8f38c817 to your computer and use it in GitHub Desktop.

Select an option

Save alexander-arce/2db0eed4968a8f38c817 to your computer and use it in GitHub Desktop.
Postgresql, change owner
--Tables
SELECT 'ALTER TABLE '|| schemaname || '.' || tablename ||' OWNER TO ccaprod;'
FROM pg_tables WHERE NOT schemaname IN ('pg_catalog', 'information_schema')
ORDER BY schemaname, tablename;
--Sequences
SELECT 'ALTER SEQUENCE '|| sequence_schema || '.' || sequence_name ||' OWNER TO ccaprod;'
FROM information_schema.sequences WHERE NOT sequence_schema IN ('pg_catalog', 'information_schema')
ORDER BY sequence_schema, sequence_name;
--Views
SELECT 'ALTER VIEW '|| table_schema || '.' || table_name ||' OWNER TO ccaprod;'
FROM information_schema.views WHERE NOT table_schema IN ('pg_catalog', 'information_schema')
ORDER BY table_schema, table_name;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment