Re: Record with a field consisting of table rows

Поиск
Список
Период
Сортировка
От Alban Hertroys
Тема Re: Record with a field consisting of table rows
Дата
Msg-id 0186A49E-B166-4EF7-8288-A98E4253D05C@solfertje.student.utwente.nl
обсуждение исходный текст
Ответ на Re: Record with a field consisting of table rows  (Jon Smark <jon.smark@yahoo.com>)
Ответы Re: Record with a field consisting of table rows
Список pgsql-general
On 15 Jan 2011, at 17:01, Jon Smark wrote:

> Hi,
>
>> Nope, see my reply from yesterday around 20:23
>> You can return a table instead, with the count added as an
>> extra column.
>
> I did see your solution, but note that it does not return a tuple
> consisting of an integer and a setof (as I wanted), but instead
> returns a setof of a tuple.

No, of course not. A function cannot return different amounts of different return-values in any language I know of.

You don't seem to grasp the essence of what a set-returning function does; they are similar to Iterators in Java or
functionsthat yield a result (as opposed to returning one) in Python or cursors in SQL. 
You can't mix that with returning a single value, unless you do that each time the function is called for the next
iteration(which happens to be what I did in my earlier example). 

You could do something ugly by collecting the results in memory until you eventually return them in an array, but that
wouldhardly be practical if your data sets get a little large. 

You probably can return a tuple consisting of an int and a refcursor though. You'll need another function to loop
throughthe refcursor to fetch the results, but you would sort of get what you apparently want. I can't see why you'd
wantthat though. 

You may also be able to return the count as an OUT-parameter, but I'm not sure you can mix that with returning a SETOF
somethingelse. I expect you'll find out that isn't possible. Obtaining both results from the function (if it _is_
possible)will be tricky I think. 

Alban Hertroys

--
If you can't see the forest for the trees,
cut the trees and you'll see there is no forest.


!DSPAM:737,4d31da3e11871342110173!



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

Предыдущее
От: Jon Smark
Дата:
Сообщение: Re: Record with a field consisting of table rows
Следующее
От: "Jaiswal Dhaval Sudhirkumar"
Дата:
Сообщение: Re: HA solution