简体   繁体   中英

Postgres array column accidentally made to text, how can I convert it back to a text array?

There's a column in my database that's a text column that should be an array column. All of the values of that column are valid Postgres arrays (since they were taken as text values from a Postgres array column) with format like {valuea,valueb} . I need them as array values however, so how do I convert them back to array values?

You may use ALTER TABLE.. ALTER COLUMN with the USING option

alter table t alter column col type text[] using col::text[];

Demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM