Skip to content

Instantly share code, notes, and snippets.

@johannesberdin
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johannesberdin/351ce3f027b9e619c5f5 to your computer and use it in GitHub Desktop.
Save johannesberdin/351ce3f027b9e619c5f5 to your computer and use it in GitHub Desktop.
Generates ALTER TABLE queries for lowercased column names and table names
/* Lowercases column names */
SELECT 'ALTER TABLE ' || quote_ident(c.table_schema) || '.' || quote_ident(c.table_name) || ' RENAME ' || quote_ident(c.column_name) || ' TO ' || quote_ident(lower(c.column_name)) || ';' As ddlsql FROM information_schema.columns As c WHERE c.table_schema NOT IN('information_schema', 'pg_catalog') AND c.column_name <> lower(c.column_name) ORDER BY c.table_schema, c.table_name, c.column_name;
/* Lowercases table names */
SELECT 'ALTER TABLE ' || quote_ident(c.table_schema) || '.' || quote_ident(c.table_name) || ' RENAME TO ' || quote_ident(lower(c.table_name)) || ';' As ddlsql FROM information_schema.tables As c WHERE c.table_schema NOT IN('information_schema', 'pg_catalog') AND c.table_name <> lower(c.table_name) ORDER BY c.table_schema, c.table_name;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment