Reputation: 839
I have a column with array datatype.Below is the data
col1
{1001,23,SAM}
{2001,34,AS}
I am trying to replace ',' with '-' and also store the data in square brackets instead of {}
col1
[1001-23-SAM]
[2001-34-AS]
Upvotes: 0
Views: 55
Reputation: 5803
This should work if you are using a version earlier than 9.4
select '[' || array_to_string(col1, '-') || ']' from your_table;
Upvotes: 0
Reputation:
The curly braces or commas aren't actually stored. It's just the default display format for arrays in Postgres, so you can't really change that.
But you can display the array differently when selecting it:
select concat('[', array_to_string(col1, '-'), ']')
from the_table;
Online example: https://rextester.com/MCWKPM72656
Upvotes: 1