Question

I am trying to change length of a column from character varying(40) to character varying(100).

Following the method described in this question Increasing the size of character varying type in postgres without data loss

ALTER TABLE info_table ALTER COLUMN docs TYPE character varying(100);

Tried with this command but returning syntax error

ERROR: syntax error at or near "TYPE" at character 52

Is there any change needed in this command? Using PostgreSQL version 7.4.30 (upgrade to 9.2 in process :) ).

I tried this same command in test db which is now upgraded with version 9.2. It is working fine there.

Was it helpful?

Solution

Changing the column type on the fly was not possible in the ancient version 7.4. Check the old manual. You had to add another column, update it with the (possibly transformed) values and then drop the old one, rename the new one - preferably in a single transaction. With side effects on views or other depending objects ...

To avoid this kind of problem altogether I suggest to use plain text or varchar (without length modifier) for character data. Details in this related question.

OTHER TIPS

Remove the word TYPE, that syntax wasn't recognized 10 years ago, but you should be fine without it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top