Re: Join field values

Поиск
Список
Период
Сортировка
От Erwin Brandstetter
Тема Re: Join field values
Дата
Msg-id 1181074459.104176.121520@q75g2000hsh.googlegroups.com
обсуждение исходный текст
Ответ на Re: Join field values  (Ragnar <gnari@hive.is>)
Ответы Re: Join field values
Список pgsql-general
On Jun 5, 7:39 pm, g...@hive.is (Ragnar) wrote:
>
> create an aggregate function and use that in your
select.http://www.postgresql.org/docs/8.2/static/sql-createaggregate.html

Of course you could do that. And it would look like that:


CREATE OR REPLACE FUNCTION f_concat_comma(text, text)
  RETURNS text AS
$BODY$
BEGIN
RETURN $1 || ', ' || $2;
END;
$BODY$
  LANGUAGE 'plpgsql' STABLE IMMUTABLE;

CREATE AGGREGATE concat_comma(
  BASETYPE=text,
  SFUNC=f_concat_comma,
  STYPE=text
);

SELECT concat_comma(field1) FROM mytbl;

--Or, if want the values ordered:
SELECT concat_comma(field1) FROM (SELECT field1 FROM mytbl ORDER by
field1)  x;


And that's what I did - before I found out about this simpler way:

SELECT array_to_string(ARRAY(SELECT field1 FROM mytbl ORDER by
field1), ', ');

More info:
http://www.postgresql.org/docs/8.2/static/functions-array.html


Regards
Erwin


В списке pgsql-general по дате отправления:

Предыдущее
От: Erwin Brandstetter
Дата:
Сообщение: Re: There can be only one! How to avoid the "highlander-problem".
Следующее
От: "Joris Dobbelsteen"
Дата:
Сообщение: Re: Creditcard Number Security was Re: Encrypted column