Last active
April 29, 2025 18:15
-
-
Save giovannicandido/046a6142eb8872712b948598cc4e01ce to your computer and use it in GitHub Desktop.
Rename pascal case tables to snake case 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(t.table_schema) || '.' | |
|| quote_ident(t.table_name) || ' RENAME TO ' As ddlsql, quote_ident(lower(regexp_replace(t.table_name, E'([A-Z])', E'\_\\1','g'))) || ';' as name | |
FROM information_schema.tables As t | |
WHERE t.table_schema NOT IN('information_schema', 'pg_catalog') | |
AND t.table_name <> lower(t.table_name) | |
ORDER BY t.table_schema, t.table_name) x; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you very much.
Rename "camelCaseColumnNames":
ChatGPT and other LLMs can help in generating similar queries for other cases, including enum types, different cases, etc.