1

I would like to change data type of a column in PostgreSQL:

alter column camelCaseColumn TYPE uuid USING uuid(camelCaseColumn)

But I can't seem to find a way to do it. The trouble is when I use double quotes in uuid call, I get an error:

invalid input syntax for uuid: ""

Is there something wrong with my approach or is there a way to accomplish this.

0

1 Answer 1

4

The error message seems to indicate that you are converting from a text (or varchar) column to uuid and you have empty strings ('') in that column. In that case you need to treat them as NULL. The name of the column is irrelevant for that error.

alter column camelCaseColumn TYPE uuid USING uuid(nullif(camelCaseColumn, ''));

However, if you really created mixed cased columns (which is a bad idea to start with) you have to use double quotes to refer to them:

alter column "camelCaseColumn" TYPE uuid USING uuid(nullif("camelCaseColumn", ''));
1
  • Thanks, man, I never considered a possibility of this being a runtime error. Commented Feb 8, 2019 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.