By default, all you identifiers are case insensitive, and internally PostgreSQL stores them in lowercase. In case you need to have:
- case sensitive
- non-ASCII characters
- special characters
within your identifiers, you should use double quotes ("
) around your identifiers.
Please, check this bit of the PostgreSQL documentation.
EDIT: After your clarification, you can use:
SELECT 'ALTER TABLE '||quote_ident(t.relname)||' RENAME TO '||t.relname||';'
FROM pg_class t, pg_namespace s
WHERE s.oid = t.relnamespace AND s.nspname = 'public'
AND t.relkind='r' AND t.relname != lower(t.relname)
ORDER BY 1;
and for columns:
SELECT 'ALTER TABLE '||quote_ident(t.relname)||
' RENAME COLUMN '||quote_ident(a.attname)||
' TO '||a.attname||';'
FROM pg_class t, pg_namespace s, pg_attribute a
WHERE s.oid = t.relnamespace AND s.nspname = 'public'
AND t.relkind='r'
AND a.attrelid = t.oid AND NOT a.attisdropped AND a.attnum > 0
AND a.attname != lower(a.attname)
ORDER BY 1;
Then copy-paste the output into your client.
If you're using psql
, you can use \t
to enable rows-only mode, \o <full_file_path>
to save output into the temporary file and, finally, \i <full_file_path>
to execute actual statements.