How to put the first element of csv string into the last column in Postgres.

Martin1920 1 Reputation point
2021-02-23T13:00:57.597+00:00

I have a column with comma-separated values and I want to split it into fixed-size columns. I have used the split_part function to do so but the values in columns should appear from the right side. Example:

Table with a single column

a1, b1, c1
a2, b2, c2, d2, e2, f2
a3, b3, c3, d3, e3, f3, g3, h3, i3, j3
a4
a5, b5, c5
'
'
'

Output i got using split_part():

c1 c2 c3 c4 c5
---------------
a1 b1 c1
a2 b2 c2 d2 e2 
f2
a3 b3 c3 d3 e3
f3 g3 h3 i3 j3
a4
a5 b5 c5
'
'
'

Expected output:

c1  c2  c3  c4  c5
------------------
        c1  b1  a1
'
'
'

so on...

Azure Database for PostgreSQL
{count} votes

1 answer

Sort by: Most helpful
  1. Navtej Singh Saini 4,216 Reputation points Microsoft Employee
    2021-02-27T02:31:42.657+00:00

    @Martin1920

    Please check if this thread helps or we would recommend to raise this issue with Postgresql community.

    Regards
    Navtej S

    0 comments No comments