Re: Record with a field consisting of table rows

Поиск
Список
Период
Сортировка
От Jon Smark
Тема Re: Record with a field consisting of table rows
Дата
Msg-id 378004.49721.qm@web112801.mail.gq1.yahoo.com
обсуждение исходный текст
Ответ на Re: Record with a field consisting of table rows  (Alban Hertroys <dalroi@solfertje.student.utwente.nl>)
Ответы Re: Record with a field consisting of table rows
Список pgsql-general
Hi,

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

Come on, you make it sound like it's something inconceivable or exotic,
even though pretty much any strongly-typed language with a post-1970s
type-system will allow a function to return tuples of arbitrary values.
Have you never come across Ocaml, Haskell, Scala, and so forth?


> You don't seem to grasp the essence of what a set-returning
> function does; they are similar to Iterators in Java or
> functions that 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 would hardly 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
> through the refcursor to fetch the results, but you would
> sort of get what you apparently want. I can't see why you'd
> want that though.

Yes, the alternatives are indeed more cumbersome than they're worth.
I might as well split the original function into two separate functions...

Cheers,
Jon





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

Предыдущее
От: Rich Shepard
Дата:
Сообщение: Re: How to generate unique invoice numbers foreach day
Следующее
От: Jon Hoffman
Дата:
Сообщение: resizing a varchar column on 8.3.8