Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save 00krishna/6ef83acdc7c97919b9554587d1bf8ab7 to your computer and use it in GitHub Desktop.
Save 00krishna/6ef83acdc7c97919b9554587d1bf8ab7 to your computer and use it in GitHub Desktop.
-- As David Fetter kindly pointed out, this looks cleaner, returns one record per ddl and is more psql friendly
SELECT 'ALTER TABLE ' || quote_ident(c.table_schema) || '.'
|| quote_ident(c.table_name) || ' RENAME "' || 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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment