From: | Alvaro Herrera <alvherre(at)commandprompt(dot)com> |
---|---|
To: | gbas gbas <gbas13(at)gmail(dot)com> |
Cc: | pgsql-es-ayuda(at)postgresql(dot)org |
Subject: | Re: Pgplsql extraño |
Date: | 2007-01-24 15:41:31 |
Message-ID: | 20070124154131.GS26006@alvh.no-ip.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-es-ayuda |
gbas gbas escribió:
> Se trata de leer un campo de la tabla y hacer con él una cadena separada
> por
> comas. El problema está en la concatenación, increiblemente no funciona
> !!.
Eso se hace de la siguiente manera en Postgres:
CREATE OR REPLACE FUNCTION concat_comma(text, text) RETURNS text AS '
BEGIN
IF $1 IS NULL THEN
RETURN $2;
ELSIF $2 IS NULL THEN
RETURN $1;
ELSE
RETURN $1 || '', '' || $2;
END IF;
END;
' LANGUAGE 'plpgsql';
CREATE AGGREGATE char_comma_sum (basetype = text, sfunc = CONCAT_COMMA, stype = text);
Luego
SELECT char_comma_sum(campo1) FROM tabla1;
--
Alvaro Herrera http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.
From | Date | Subject | |
---|---|---|---|
Next Message | Andres Duque | 2007-01-24 15:55:28 | Re: modelo de desarrollo cliente servidor en postgresql |
Previous Message | Juan Martínez | 2007-01-24 15:27:28 | Re: configurar el pg_hba |