Re: plpgsql setof help

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: plpgsql setof help
Дата
Msg-id 6023.1233188981@sss.pgh.pa.us
обсуждение исходный текст
Ответ на plpgsql setof help  ("Matthew T. O'Connor" <matthew@zeut.net>)
Ответы Re: plpgsql setof help  (Frank Bax <fbax@sympatico.ca>)
Список pgsql-sql
"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'

> In order to do this, I think I would have to create a pl/pgsql function 
> that accpts a setof text argument, but I'm not sure that's allowed.  

Well, if you are okay with writing

select column_to_english_list( 'select towns from towns_table' );

(ie, pass the subquery as a string) then you could do something
involving FOR ... IN EXECUTE $1.

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.
        regards, tom lane


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

Предыдущее
От: "Matthew T. O'Connor"
Дата:
Сообщение: plpgsql setof help
Следующее
От: Frank Bax
Дата:
Сообщение: Re: plpgsql setof help