Skip to content

Instantly share code, notes, and snippets.

Created December 18, 2012 16:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/4329659 to your computer and use it in GitHub Desktop.
Save anonymous/4329659 to your computer and use it in GitHub Desktop.
scripts to lowercase column and table names to make PostgreSQL data less annoying to work with I found this here: http://www.postgresonline.com/journal/archives/141-Lowercasing-table-and-column-names.html
--#lowecase table and field names scripts:
--(generates the sql needed; best to do in psql command line)
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;
--and
SELECT 'ALTER TABLE ' || quote_ident(t.table_schema) || '.'
|| quote_ident(t.table_name) || ' RENAME TO ' || quote_ident(lower(t.table_name)) || ';' As ddlsql
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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment