Re: JOIN results of refcursor functions

From: Milan Oparnica <milan(dot)opa(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: JOIN results of refcursor functions
Date: 2008-12-02 23:10:59
Message-ID: gh4f5l$24iq$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Milan Oparnica wrote:

>> Then I've tried:
>>
>> CREATE FUNCTION foo(insklid int, out sklid int, out elid INT) RETURNS SETOF record AS $$
>> BEGIN
>> RETURN QUERY SELECT sklid,elid FROM skladkol;
>> RETURN;
>> END;
>> $$ LANGUAGE plpgsql;
>>
>> but it returns 5498 rows (which is exact number of rows in that table) but of NULL values. WHAT AM I DOING WRONG ? :(((
>> ....

Pavel Stehule wrote:

> know bug :( - your variable names are in collision with column names.
> You have to protect self - use prefixes for variables
>

Thanks Pavel, fortunately if you select columns by table reference
(table.field) collision is avoided:

CREATE FUNCTION foo(insklid int, out sklid int, out elid INT) RETURNS
SETOF record AS $$
BEGIN
RETURN QUERY SELECT skladkol.sklid, skladkol.elid FROM skladkol;
RETURN;
END;
$$ LANGUAGE plpgsql;

This works fine.

Interesting thing is that using OUT parameters performs much faster than
using SETOF custom composite type when returning large recordsets.

Is this bug coming soon on some to-do-fix-list ?

This structure seems to be nice replacement for PERSISTANT PREPARE I was
posting some months ago, the only mess is out variables position
sensitivity - you must ensure that select statement returns values in
exact order as out parameters are declared.

Best regards,

Milan Oparnica

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Gary Stainburn 2008-12-04 10:01:46 constraint question (I think)
Previous Message Shane Ambler 2008-12-02 16:30:34 Re: how to update 400 000 register not at the same time?