0

I am trying to figure out how to use array_to_string in PostgreSQL to change a column's data type. Currently my column has arrays, for example: ["7856", "2345"]. Which I would like to change to a string: 7856, 2345.

Currently I can just do this with SELECT but can't figure out how to alter the data. So far I have just been using:

SELECT array_to_string(myColumnn,',') as myColumn from myTable

Is there a way to use this to permanently change the data type in the column?

Thank you

1
  • Storing delimited values in a column is a bad design decision to begin with. But if you really want to de-normalize your data, then at least stick with proper arrays rather than the dreaded comma separated values. Commented Dec 6, 2022 at 21:30

1 Answer 1

0
ALTER TABLE myTable
ALTER COLUMN myColumn TYPE VARCHAR 
USING array_to_string(myColumnn, ',');

Documentation

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.