moberemk
moberemk

Reputation: 1625

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?

Upvotes: 0

Views: 145

Answers (1)

Kaushik Nayak
Kaushik Nayak

Reputation: 31666

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

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

Demo

Upvotes: 1

Related Questions