Changing table data type from varchar to text postgressql

I have a problem and search for a solution on Google, but I can not find it. I have a posgre Tabel named products_199 and in this table there is a column called parameter2 type varchar (255). I want to change the data type to text, but somehow I get the following error:

ERROR:  parser: parse error at or near "TYPE" at character 50

My command is as follows what I want to execute

ALTER TABLE products_199 ALTER COLUMN parameter2 TYPE text;

I am using PostgreSQL 7.3.4

+3
source share
1 answer

I think the syntax is only available in newer versions of PostgreSQL.

If you cannot change versions (7.3.4 is quite old), I suggest you just add a new column, copy the data and delete the old column. This would be the safest way imo.

- ( , !)

begin; 
alter table products_199 add column parameter2_n text; 
update products_199 set parameter2_n=parameter2; 
alter table products_199 drop column parameter2;
commit;
vacuum; 
+3

Source: https://habr.com/ru/post/1712278/


All Articles