通过分隔符拆分列数据类型从文本更改为数组

mrp*_*pyo 3 postgresql types alter-table

我需要更改列数据类型。它包含形式为的文本"part1 part2 part3"

我希望将其内容表示为数组(["part1", "part2", "part3"])。

最简单的方法是什么?我需要编写程序还是可以仅使用SQL来完成?

我正在使用PostgreSQL。

a_h*_*ame 5

如果只想选择它作为数组:

select string_to_array(your_column, ' ')
from your_table;
Run Code Online (Sandbox Code Playgroud)

如果您永久希望将数据类型更改为例如text[]

alter table your_table 
      alter your_column type text[] using string_to_array(your_column, ' ');
Run Code Online (Sandbox Code Playgroud)