Skip to content

Instantly share code, notes, and snippets.

@jnm
Last active October 15, 2018 18:31
Show Gist options
  • Save jnm/23a514b5db4290b09ede to your computer and use it in GitHub Desktop.
Save jnm/23a514b5db4290b09ede to your computer and use it in GitHub Desktop.
Change owner of all tables in a database using pure PostgreSQL
DO
$$
DECLARE
row record;
BEGIN
FOR row IN SELECT table_name FROM information_schema.tables
WHERE table_schema <> 'pg_catalog' AND table_schema <> 'information_schema' AND table_catalog = 'kobotoolbox'
LOOP
EXECUTE 'ALTER TABLE ' || quote_ident(row.table_name) || ' OWNER TO kobo;';
END LOOP;
END;
$$;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment