When I tried to rename a CamelCase column like this:
ALTER TABLE mytable RENAME COLUMN camelCaseColumn TO camel_case_column;
I get the following error:
ERROR: column "camelcasecolumn" does not exist
Surrounding the CamelCase column name with single quotes like this:
ALTER TABLE mytable RENAME COLUMN 'camelCaseColumn' TO camel_case_column;
gives me a syntax error.
Is there any way I can rename the column? Or do I have to create a new table and transfer the data?
The database is running on Ubuntu, and I am using Mac OS X to ssh into the server where the database is running on to issue the ALTER TABLE
commands. I know that Mac OS X is case insensitive, so could this be part of the problem?
Thanks!
2 Answers 2
Turns out that using double quotes works:
ALTER TABLE mytable RENAME COLUMN "camelCaseColumn" TO camel_case_column;
-
3Yes, PostgreSQL case-folds unquoted identifiers, per the SQL spec requirements. See the documentation: postgresql.org/docs/current/static/sql-syntax-lexical.htmlCraig Ringer– Craig Ringer2014年02月10日 03:23:38 +00:00Commented Feb 10, 2014 at 3:23
If you wish to migrate all of the column names in the database to the PostgreSQL convention, check out my post here