以下DDL將列轉換爲數組,並使現有值成爲第一個數組元素:
alter table the_table
alter column x type varchar(255)[] using array[x];
如果想要撤銷更改可以使用相同的邏輯
alter table the_table
alter column x type varchar(255) using coalesce(x[1],'');
x [1]返回第一個元素,但僅在數組爲空時返回null。 使用Coalesce()然後可以將其轉換爲空字符串’’