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

标签 postgresql types alter-table

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

我希望它的内容被表示为一个数组 (["part1", "part2", "part3"])。

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

我正在使用 PostgreSQL。

最佳答案

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

select string_to_array(your_column, ' ')
from your_table;

如果您想要永久更改数据类型,例如 text[],请使用:

alter table your_table 
      alter your_column type text[] using string_to_array(your_column, ' ');

关于postgresql - 通过分隔分隔符将列数据类型从文本更改为数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27195460/

相关文章:

php - PDO 查询更新不在查询第 2 部分中的日期时间列

SQL SET DEFAULT 在 MS Access 中不起作用

postgresql - SQLAlchemy SELECT WITH 子句/语句 (pgsql)

oracle - 提高查询性能——从oracle中选择数据到postgresql

Python SQLite 错误绑定(bind),带字符串的类型不受支持

java - 如何重构 "stringly-typed"代码?

postgresql - 如何在 PostgreSQL 中更改 "REFERENCES"?

java - JPA hibernate : Invalid persistence. xml

sql基本if else条件

Python 字符串到其他类