Re: Record with a field consisting of table rows - Mailing list pgsql-general

From Alban Hertroys
Subject Re: Record with a field consisting of table rows
Date
Msg-id 685C2671-5DA2-497C-B507-656D705F9509@solfertje.student.utwente.nl
Whole thread Raw
In response to Re: Record with a field consisting of table rows  (Jon Smark <jon.smark@yahoo.com>)
Responses Re: Record with a field consisting of table rows  (Jon Smark <jon.smark@yahoo.com>)
List pgsql-general
On 15 Jan 2011, at 21:57, Jon Smark wrote:

>> 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?


A tuple wouldn't be unusual, but you're not asking for a simple tuple here. What you're asking for is a value and a set
oftuples. That would sort of look like this: 

total | users
---------------------------------------------------------
 3    | foo
      | bar
      | baz

And what's worse, after the first returned tuple you only seem to want the users value, without the total value. I
don'tknow of any language that can do that and I'm pretty sure the languages you mentioned can't do that either. It
makesparsing the return values unnecessary difficult, I bet that's a compelling enough reason that nobody seems to have
implementedit. 


What most languages, including pgsql, _can_ do is this:

total | users
---------------------------------------------------------
 3    | foo
 3    | bar
 3    | baz


Or this:

total | users
---------------------------------------------------------
 3    | [foo, bar, baz]


Alban Hertroys

--
Screwing up is an excellent way to attach something to the ceiling.


!DSPAM:737,4d32398a11872893390349!



pgsql-general by date:

Previous
From: Вячеслав Блинников
Date:
Subject: libpq: multiple commands within single query
Next
From: Alban Hertroys
Date:
Subject: Re: Trigger Performance