Created
June 12, 2016 02:28
-
-
Save giovannicandido/e717109fc4598f1ab16598d2f9433c0d to your computer and use it in GitHub Desktop.
Rename pascal column names to snake case columns names in postgresql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT ddlsql || regexp_replace(name, E'^_',E'','g') || ';' as ddlsql FROM | |
( | |
SELECT 'ALTER TABLE ' || quote_ident(c.table_schema) || '.' | |
|| quote_ident(c.table_name) || ' RENAME "' || c.column_name || '" TO ' As ddlsql, quote_ident(lower(regexp_replace(column_name, E'([A-Z])', E'\_\\1','g'))) as name | |
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 | |
) x; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment