Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alter character varying column's length in PostgreSQL

I have table in production which has column type character varying(255);

All rows has entry in that column no longer than 15 characters and never will be larger as well. I decide to reduce its size to 15 characters with following command which I found on sof:

ALTER TABLE user_template ALTER COLUMN "TYPE" character varying(15);

I got following error:

ERROR:  syntax error at or near "character"
LINE 1: ...LTER TABLE user_template ALTER COLUMN "type" character ...
                                                        ^

Can you help me to fix it? Thanks.

like image 575
Aligator Avatar asked Dec 23 '22 09:12

Aligator


1 Answers

create table user_template (field1 varchar(255));
ALTER TABLE user_template ALTER COLUMN field1 TYPE varchar(15);

dbfiddle here

like image 70
McNets Avatar answered Dec 29 '22 05:12

McNets