From: | Jon Smark <jon(dot)smark(at)yahoo(dot)com> |
---|---|
To: | Alban Hertroys <dalroi(at)solfertje(dot)student(dot)utwente(dot)nl> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Record with a field consisting of table rows |
Date: | 2011-01-15 20:57:50 |
Message-ID: | 378004.49721.qm@web112801.mail.gq1.yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | Jon Hoffman | 2011-01-15 21:22:50 | resizing a varchar column on 8.3.8 |
Previous Message | Rich Shepard | 2011-01-15 20:38:44 | Re: How to generate unique invoice numbers foreach day |