How do I concatenate row-wise instead of column-wise?
От | Marcus Claesson |
---|---|
Тема | How do I concatenate row-wise instead of column-wise? |
Дата | |
Msg-id | 3D33D4AA.1020600@angiogenetics.se обсуждение исходный текст |
Ответы |
Re: How do I concatenate row-wise instead of column-wise?
Re: How do I concatenate row-wise instead of column-wise? |
Список | pgsql-sql |
I have a table like this: SELECT * FROM old_tab; id | descr ------------------- 1 | aaa 1 | aaa 1 | bbb 2 | ccc 2 | bbb 3 | ddd 3 | ddd 3 | eee 3 | fff 4 | bbb etc... And I want a new table where the descr is concatenated row-wise like this: SELECT * FROM new_tab; id | descr -------------------------- 1 | aaa;bbb 2 | ccc;bbb 3 | ddd;eee;fff 4 | bbb etc... This is the closest I get....: UPDATE new_tab SET descr = old_tab.descr||' ; '||old_tab.descr from old_tab where old_tab.id=new_tab.id; UPDATE 4 SELECT * FROM new_tab ;id | descr ----+-----------1 | aaa ; aaa2 | ccc ; ccc3 | ddd ; ddd4 | bbb ; bbb etc... Thus, the concatenating operator never works on other rows than the present. How can I get around that and still stick to the postgresql syntax? Regards Marcus
В списке pgsql-sql по дате отправления: