Re: Concatenation through SQL
От | Niklas Johansson |
---|---|
Тема | Re: Concatenation through SQL |
Дата | |
Msg-id | 520638AC-01E3-48C6-A480-DEB5E56139E5@tele2.se обсуждение исходный текст |
Ответ на | Re: Concatenation through SQL ("Leif B. Kristensen" <leif@solumslekt.org>) |
Ответы |
Re: Concatenation through SQL
|
Список | pgsql-sql |
On 21 dec 2007, at 12.16, Leif B. Kristensen wrote: > I've got a similar problem. My persons table has a number of fields > for > different name parts: given, patronym, toponym, surname, occupation, > epithet. > I'd like something more elegant, like the > Python or PHP join() function. I tried Andreas' suggestion like this: > > pgslekt=> select array_to_string(array(select given, patronym, toponym > from persons where person_id=57), ' '); > ERROR: subquery must return only one column Your case is not the same as Philippe's, since you have the values to be concatenated in columns, whereas he had them in rows. However, something like this would probably achieve what you're looking for: select array_to_string(array[given, patronym, toponym], ' ') from persons where person_id=57; Notice the use of the array[] constructor, instead of the array() constructor, which must be fed a subquery which returns only one column.
В списке pgsql-sql по дате отправления: