Skip site navigation (1) Skip section navigation (2)

Re: Concatenating several rows

From: "Pierre Thibaudeau" <pierdeux(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: Concatenating several rows
Date: 2007-01-30 04:10:20
Message-ID: 74b035bb0701292010p7dc7e341s938262bef19f48e0@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-novice
Thank you, George and Phillip!  I was trying something similar (doing
a cast) which wasn't working:

SELECT array_to_string( (SELECT name FROM pseudonyms WHERE
person_id=125)::array, ' ');


In the meantime, I wrote a little function to do the job, but your
solution is simpler:

CREATE OR REPLACE FUNCTION persons.aggregatenames(personid integer)
  RETURNS text AS
$BODY$declare
somerow record DEFAULT '';
thenames text;
BEGIN
FOR somerow IN SELECT name FROM pseudonyms WHERE person_id=personid LOOP
	thenames := thenames || ' ' || somerow.name ;
END LOOP;
RETURN thenames;
END;$BODY$
  LANGUAGE 'plpgsql' STABLE;



> SELECT array_to_string(array(SELECT name FROM pseudonyms WHERE
> person_id=125), ' ');

In response to

pgsql-novice by date

Next:From: BottiniDate: 2007-01-30 11:06:52
Subject: how install 2 different version
Previous:From: George PavlovDate: 2007-01-30 03:30:02
Subject: Re: Concatenating several rows

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group