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

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Re: Concatenating several rows



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), ' ');



Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group