pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: imad <immaad@gmail.com>
To: Leif B. Kristensen <leif@solumslekt.org>
Cc: pgsql-sql@postgresql.org
Subject: Re: Concatenation through SQL
Date: Fri, 21 Dec 2007 16:51:58 +0500
Message-ID: <1f30b80c0712210351v383d9a8cxbd6d085d1646841d@mail.gmail.com> (raw)
In-Reply-To: <200712211216.45186.leif@solumslekt.org>
References: <6C0CF58A187DA5479245E0830AF84F42337F97@poweredge.attiksystem.ch>
	<200712211216.45186.leif@solumslekt.org>

On Dec 21, 2007 4:16 PM, Leif B. Kristensen <leif@solumslekt.org> wrote:
> On Friday 21. December 2007, Philippe Lang wrote:
>
> >(SELECT CONCAT(name, ', ') FROM employees AS e where e.appointment_id
> > = appointments.id) AS employees
> >FROM appointments
> >------------------------------
> >
> >... where CONCAT suggest we want to concatenate the variable inside,
> >with the separator ', ' inbetween.
>
> 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've written a Plpgsql function that concatenates the full
> name, but it's big and ugly. 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

Try concatenating your columns using the '||' operator or 'concat' function
and project only one column from the subquery. You won't need to convert it
to an array and back to string.


--Imad
Database Expert



view thread (10+ messages)  latest in thread

Message-ID: <1f30b80c0712210351v383d9a8cxbd6d085d1646841d@mail.gmail.com>
Permalink:  ../1f30b80c0712210351v383d9a8cxbd6d085d1646841d@mail.gmail.com/
Also on:    postgresql.org/message-id/1f30b80c0712210351v383d9a8cxbd6d085d1646841d@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: immaad@gmail.com, leif@solumslekt.org
  Subject: Re: Concatenation through SQL
  In-Reply-To: <1f30b80c0712210351v383d9a8cxbd6d085d1646841d@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox