Aligator
Aligator

Reputation: 737

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.

Upvotes: 5

Views: 15558

Answers (1)

McNets
McNets

Reputation: 10817

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

dbfiddle here

Upvotes: 12

Related Questions