PL/pgsql return more than one values

Lists: pgsql-general
From: Richard Emberson <emberson(at)phc(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: PL/pgsql return resultset/cursor?
Date: 2002-03-23 01:14:07
Message-ID: 3C9BD6DF.E5EF582E@phc.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general


Is it possible to return a result-set or cursor from a PL/pgsql
procedure, like

CREATE OR REPLACE FUNCTION foo()
RETURNS <WHAT_TYPE> AS '
BEGIN
RETURN SELECT * from FOO;
END;
' LANGUAGE 'plpgsql';

If you open a cursor in a procedure, it gets closed when the procedure
exits, right?

Richard


From: Jan Wieck <janwieck(at)yahoo(dot)com>
To: Richard Emberson <emberson(at)phc(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: PL/pgsql return resultset/cursor?
Date: 2002-03-23 10:54:11
Message-ID: 200203231054.g2NAsB217580@saturn.janwieck.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Richard Emberson wrote:
>
> Is it possible to return a result-set or cursor from a PL/pgsql
> procedure, like
>
> CREATE OR REPLACE FUNCTION foo()
> RETURNS <WHAT_TYPE> AS '
> BEGIN
> RETURN SELECT * from FOO;
> END;
> ' LANGUAGE 'plpgsql';
>
> If you open a cursor in a procedure, it gets closed when the procedure
> exits, right?

Cursors get closed in PostgreSQL when you close them or when
the transaction ends.

Look at the refcursor data type (new in v7.2) and use
transactions.

Jan

--

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck(at)Yahoo(dot)com #

_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Jan Wieck <janwieck(at)yahoo(dot)com>
Cc: Richard Emberson <emberson(at)phc(dot)net>, pgsql-general(at)postgresql(dot)org
Subject: Re: PL/pgsql return resultset/cursor?
Date: 2002-03-23 14:38:18
Message-ID: 200203231438.g2NEcIK16492@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Jan Wieck wrote:
> Richard Emberson wrote:
> >
> > Is it possible to return a result-set or cursor from a PL/pgsql
> > procedure, like
> >
> > CREATE OR REPLACE FUNCTION foo()
> > RETURNS <WHAT_TYPE> AS '
> > BEGIN
> > RETURN SELECT * from FOO;
> > END;
> > ' LANGUAGE 'plpgsql';
> >
> > If you open a cursor in a procedure, it gets closed when the procedure
> > exits, right?
>
> Cursors get closed in PostgreSQL when you close them or when
> the transaction ends.
>
> Look at the refcursor data type (new in v7.2) and use
> transactions.

Here is a sample:

create table aa(a int, b int, c int);
create function f() returns refcursor as '
declare
r refcursor;
begin
open r for select * from aa;
return r;
end;' language 'plpgsql';

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026


From: "Gyorgy Molnar" <yuri(at)powercom(dot)com(dot)sg>
To: <pgsql-general(at)postgresql(dot)org>
Subject: PL/pgsql return more than one values
Date: 2002-03-26 20:32:54
Message-ID: 003801c1d505$6c023000$9b01a8c0@dell8100
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Does anyone know how to return more than one value from pgsql script?
In the archieve I've found some email about it. Somebody suggested to create
a temporary table?
Could any one make a small smaple script for me? I have postgesql 7.1.

Kind Regards,
Yuri