Skip to content

Instantly share code, notes, and snippets.

@mkoehrsen
Created March 20, 2015 19:06
Show Gist options
  • Save mkoehrsen/e51ec6f5d167158ef9a4 to your computer and use it in GitHub Desktop.
Save mkoehrsen/e51ec6f5d167158ef9a4 to your computer and use it in GitHub Desktop.
Postgres -- generate view definition mirroring every table in the public schema
select 'CREATE OR REPLACE VIEW dp_' || table_name ||
E' AS\nSELECT ' || array_to_string(array_agg(format('%s',column_name)),E',\n ') ||
E'\nFROM ' || table_name || E';\n'
from information_schema.columns
where table_schema = 'public'
group by table_name;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment