From: | Niklas Johansson <spot(at)tele2(dot)se> |
---|---|
To: | Leif B(dot) Kristensen <leif(at)solumslekt(dot)org> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Concatenation through SQL |
Date: | 2007-12-21 12:07:00 |
Message-ID: | 520638AC-01E3-48C6-A480-DEB5E56139E5@tele2.se |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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.
From | Date | Subject | |
---|---|---|---|
Next Message | Leif B. Kristensen | 2007-12-21 12:31:14 | Re: Concatenation through SQL |
Previous Message | imad | 2007-12-21 11:51:58 | Re: Concatenation through SQL |