Code:
test=*# select * from zeroseven ;
order_id | label | index | value
----------+-----------+-------+--------------
11 | vorname | 0 | max
11 | nachname | 1 | mustermann
11 | anschrift | 2 | hauptstraße2
11 | plz | 3 | 12345
11 | ort | 4 | berlin
12 | vorname | 0 | andreas
12 | nachname | 1 | egal
12 | anschrift | 2 | irgendwo
12 | plz | 3 | 4711
12 | ort | 4 | erde
(10 rows)
Time: 0,219 ms
test=*# select order_id, array_to_string(array_agg(vorname),'') as vorname, array_to_string(array_agg(nachname),'') as nachname, array_to_string(array_agg(anschrift),'') as anschrift, array_to_string(array_agg(plz),'') as plz, array_to_string(array_agg(ort),'') as ort from (select order_id, case when index=0 then value else null end as vorname, case when index=1 then value else null end as nachname, case when index=2 then value else null end as anschrift, case when index=3 then value else null end as plz, case when index=4 then value else null end as ort from zeroseven ) foo group by order_id;
order_id | vorname | nachname | anschrift | plz | ort
----------+---------+------------+--------------+-------+--------
11 | max | mustermann | hauptstraße2 | 12345 | berlin
12 | andreas | egal | irgendwo | 4711 | erde
(2 rows)
Mache Dich mit Formatierungsmöglichkeiten hier im Forum vertraut.