Increasing the size of character varying type in postgres without data loss

The correct query to change the data type limit of the particular column:

ALTER TABLE client_details ALTER COLUMN name TYPE character varying(200);

Referring to this documentation, there would be no data loss, alter column only casts old data to new data so a cast between character data should be fine. But I don't think your syntax is correct, see the documentation I mentioned earlier. I think you should be using this syntax :

ALTER [ COLUMN ] column TYPE type [ USING expression ]

And as a note, wouldn't it be easier to just create a table, populate it and test :)


Yes. But it will rewrite this table and lock it exclusively for duration of rewriting — any query trying to access this table will wait until rewrite finishes.

Consider changing type to text and using check constraint for limiting size — changing constraint would not rewrite or lock a table.


you can use this below sql command
ALTER TABLE client_details ALTER COLUMN name TYPE varchar(200)