Skip to content

Instantly share code, notes, and snippets.

@ramontayag
Created November 8, 2010 10:55
Show Gist options
  • Save ramontayag/667574 to your computer and use it in GitHub Desktop.
Save ramontayag/667574 to your computer and use it in GitHub Desktop.
CREATE OR REPLACE FUNCTION clone_schema_data(source_schema text, dest_schema text) RETURNS void AS
$BODY$
DECLARE
objeto text;
BEGIN
FOR objeto IN
SELECT table_name::text FROM information_schema.TABLES WHERE table_schema = source_schema
LOOP
IF objeto != 'schema_migrations' THEN
EXECUTE 'INSERT INTO ' || dest_schema || '.' || objeto || '(SELECT * FROM ' || source_schema || '.' || objeto || ')';
END IF;
END LOOP;
END;
$BODY$
LANGUAGE plpgsql VOLATILE;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment