On 16 Jan 2011, at 17:40, Jon Smark wrote:
> Again, you're making it sound like I'm requesting something exotic,
> while any language with a modern type system allows this and much
> more without blinking. In Ocaml, for example, the return type 'page_t'
> of my function could be defined as follow
Hi,
> 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 of tuples.
Which is in itself a tuple! This discussion is again veering slightly
off-topic, but note that tuples as mathematical objects do not have such
arbitrary li
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
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 func
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 w
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.
I still
On 14 Jan 2011, at 16:03, Jon Smark wrote:
> Hi,
>
> This thread has veered off-topic, but my original problem still remains.
> Basically, I want to declare a function that returns a tuple consisting
> of an integer and a set of table rows. Something like the following:
>
> CREATE FUNCTION foob
2011/1/14 Jon Smark :
> Hi,
>
> This thread has veered off-topic, but my original problem still remains.
> Basically, I want to declare a function that returns a tuple consisting
> of an integer and a set of table rows. Something like the following:
>
> CREATE FUNCTION foobar () RETURNS (int4, SET
Hi,
This thread has veered off-topic, but my original problem still remains.
Basically, I want to declare a function that returns a tuple consisting
of an integer and a set of table rows. Something like the following:
CREATE FUNCTION foobar () RETURNS (int4, SETOF users)
Now, if I understand co
2011/1/13 Alban Hertroys :
> On 13 Jan 2011, at 20:21, Pavel Stehule wrote:
>
>>> I'm not sure what you mean here, Postgres certainly _does_ support
>>> set-returning functions. Maybe you were referring to something in the
>>> particular context of the problem the OP is trying to solve?
>>>
>>
>>
On 13 Jan 2011, at 20:21, Pavel Stehule wrote:
>> I'm not sure what you mean here, Postgres certainly _does_ support
>> set-returning functions. Maybe you were referring to something in the
>> particular context of the problem the OP is trying to solve?
>>
>
> The name of feature "SET RETURNED
2011/1/13 Alban Hertroys :
> On 13 Jan 2011, at 19:25, Pavel Stehule wrote:
>
>>> The above does work, thanks. There is however one drawback: the type
>>> associated with _page.users is now an array. Is there a way to make
>>> it a 'SETOF user_t'?
>>>
>>
>> no. PostgreSQL doesn't supports SET. On
On 13 Jan 2011, at 17:22, Jon Smark wrote:
> create type page_t AS
>(
>total int4,
>users user_t[]
>);
>
> create function get_page ()
> returns page_t
> language plpgsql as
> $$
> declare
>_page page_t;
> begin
>_page.total := select count (*
On 13 Jan 2011, at 19:25, Pavel Stehule wrote:
>> The above does work, thanks. There is however one drawback: the type
>> associated with _page.users is now an array. Is there a way to make
>> it a 'SETOF user_t'?
>>
>
> no. PostgreSQL doesn't supports SET. Only arrays are supported.
I'm not
2011/1/13 Jon Smark :
> Hi,
>
>> That is certainly not going to work: that select does not produce an
>> array, it produces a column of user_t (of which SELECT INTO is only
>> gonna take the first, anyway).
>>
>> Untested, but I think you'd have better results with
>>
>> _page.users := array(se
Hi,
> That is certainly not going to work: that select does not produce an
> array, it produces a column of user_t (of which SELECT INTO is only
> gonna take the first, anyway).
>
> Untested, but I think you'd have better results with
>
> _page.users := array(select users from users limit 10
Jon Smark writes:
> create type page_t AS
> (
> total int4,
> users user_t[]
> );
> create function get_page ()
> returns page_t
> language plpgsql as
> $$
> declare
> _page page_t;
> begin
> _page.total := select count (*) from users;
>
Hello
try to SELECT INTO ARRAY(SELECT user_t FROM users LIMIT 10) _page.users;
Regards
Pavel Stehule
2011/1/13 Jon Smark :
> Hi,
>
> I am trying to create a PL/pgSQL function whose return type is a tuple
> consisting of an integer and a list of table rows. I emulate the tuple
> by defining a
Hi,
I am trying to create a PL/pgSQL function whose return type is a tuple
consisting of an integer and a list of table rows. I emulate the tuple
by defining a record 'page_t' with the two fields; however, the naïve
approach of doing a SELECT INTO one the record's fields does not work
(see functi
19 matches
Mail list logo