Re: plpgsql setof help

Поиск
Список
Период
Сортировка
От Frank Bax
Тема Re: plpgsql setof help
Дата
Msg-id 4980FD29.7060502@sympatico.ca
обсуждение исходный текст
Ответ на Re: plpgsql setof help  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-sql
Tom Lane wrote:
> "Matthew T. O'Connor" <matthew@zeut.net> writes:
>> I want the following:
>> select column_to_english_list( select towns from towns_table );
> 
>> to return:
>> 'town1, town2 and town3'
> 
> I wonder though if it wouldn't be better to recast the problem as an
> aggregate:
> 
> select column_to_english_list(towns) from towns_table;
> 
> probably using text[] as the transition state, and having the
> transition function just accumulate all the words into the array
> and then the final function decides where to plaster commas and
> "and"s.
> 
> You can find examples of similar aggregates in the PG archives, IIRC.


Actually; an example is in docs:

http://www.postgresql.org/docs/8.3/static/xaggr.html

use array_accum(); then reformat final text (to remove {} and change 
last comma to 'and').


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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: plpgsql setof help
Следующее
От: Andreas
Дата:
Сообщение: I need some magical advice