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

Martin1920 1 Reputation point

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
a5, b5, c5

Output i got using split_part():

c1 c2 c3 c4 c5
a1 b1 c1
a2 b2 c2 d2 e2 
a3 b3 c3 d3 e3
f3 g3 h3 i3 j3
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,221 Reputation points Microsoft Employee


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

    Navtej S

    0 comments No comments