Re: How do we combine and return results from multiple queries in a loop?

Поиск
Список
Период
Сортировка
От John R Pierce
Тема Re: How do we combine and return results from multiple queries in a loop?
Дата
Msg-id 4DD0B5E9.7090303@hogranch.com
обсуждение исходный текст
Ответ на How do we combine and return results from multiple queries in a loop?  (Bernardo Telles <btelles@gmail.com>)
Ответы Re: How do we combine and return results from multiple queries in a loop?
Список pgsql-general
On 05/15/11 8:53 PM, Bernardo Telles wrote:
> Hi there,
> We'd like to use a plpgsql function to use results from query A to
> execute several queries B, C, etc., and return the results of all B,
> C, etc queries as one result set. Would placing 'RETURN QUERY' inside
> a loop automatically concatenate all 'return query' results in the
> function's return? If not, how would we go about getting this result?

all the queries would have to have the same fields to do this.  if they
do, then you can write it as a join or union.

in your example case, its easy.

     select * from locations l join zipcode z on l.state = z.state where
z.zipcode like '32301%';

this also would be more efficient than the way you proposed

now, if you're thinking of a DIFFERENT problem thats more complex to
solve, well, without knowing the actual problem there's not much I can
suggest.



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

Предыдущее
От: Bernardo Telles
Дата:
Сообщение: How do we combine and return results from multiple queries in a loop?
Следующее
От: Nick Raj
Дата:
Сообщение: Toast datum