Re: PERFORM not working properly, please help..

From: wilczarz1(at)op(dot)pl
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: PERFORM not working properly, please help..
Date: 2010-02-19 09:54:43
Message-ID: Q18097777-0f3d47a22d345fd3ae96b3b9ac6871d1@pmq1.m5r2.onet.test.onet.pl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi Pavel, thanks for reply. Your solution:

CREATE OR REPLACE FUNCTION A3() RETURNS VOID AS $BODY$
begin
return query select * from A1();
return;
end;
$BODY$ LANGUAGE 'plpgsql';

generates error "cannot use RETURN QUERY in a non-SETOF function" because A3 returns VOID.


"Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com> napisał(a):
> Hello
>
> 2010/2/18 <wilczarz1(at)op(dot)pl>:
> > I have a function A1 that returns setof records, and I use it in two ways:
> > 1) from function A2, where I need results from A1
> > 2) from function A3, where I don't need these results, all I need is to
> > execute logic from A1
> >
> > Here ale very simple versions of my functions:
> >
> > CREATE OR REPLACE FUNCTION A1() RETURNS setof record AS $BODY$
> > begin
> >  -- some logic here
> >  return query select col from tab;
> > end;
> > $BODY$ LANGUAGE 'plpgsql';
> >
> > CREATE OR REPLACE FUNCTION A2() RETURNS setof record AS $BODY$
> > begin
> >  -- some logic here
> >  return query select * from A1() as dummy ( x double precision);
> > end;
> > $BODY$ LANGUAGE 'plpgsql';
> >
> > CREATE OR REPLACE FUNCTION A3() RETURNS VOID AS $BODY$
> > begin
> >  perform A1();
> > end;
> > $BODY$ LANGUAGE 'plpgsql';
> >
> > And here are my function calls:
> > select * from A1() as(x double precision) --ok
> > select * from A2() as(x double precision) --ok
> > select * from A3(); --not ok, argh!
> >
>
> it is correct. Every function has own stack for result. There are not
> some global stack. Perform just run function and doesn't copy inner
> result's stack to outer result stack.
>
> your A3 function have to be
> begin
> return query select * from a1
> return;
> end;
>
> like a2 function
>
> regards
> Pavel Stehule
> > The last one generates error "set-valued function called in context that
> > cannot accept a set". Why doesn't PERFORM work here? Thanks for help..
> >

Responses

Browse pgsql-general by date

  From Date Subject
Next Message wilczarz1 2010-02-19 09:59:54 Re: PERFORM not working properly, please help..
Previous Message Jignesh Shah 2010-02-19 09:06:44 How to get the users name from users group?