0

I have a table data like below :

enter image description here

Expected Result :

enter image description here

Query I am trying :

select Id, string_to_array(element_X::text,',')::int[] from table;

But its giving in a curly braces ( I understand, its just an array ). Is it possible to display it in a square bracket.

Result as of now :

Current Result

Is it possible to display like that

1
  • 2
    Displaying results happens on the client. It should be easy to replace the braces of the text representation with brackets in client code. Commented Dec 23, 2020 at 5:28

1 Answer 1

1

Postgresql Documentation says

The decoration consists of curly braces ({ and }) around the array value plus delimiter characters between adjacent items

Its indeed the representation of array. If you want just for display you can use something like translate.

with arry as(
select id, string_to_array(element_X::text,',')::int[] as element_X_arry from table
)
select id, translate(element_X_arry::text,'{}','[]') from arry

Demo on db<>fiddle

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.