pg.ddx.io pgsql-docs@postgresql.org mailing list archive
help / color / mirror / Atom feedRe: [GENERAL] PL/pgsql return resultset/cursor?
3+ messages / 2 participants
[nested] [flat]
* Re: [GENERAL] PL/pgsql return resultset/cursor?
@ 2002-04-09 03:34 Bruce Momjian <pgman@candle.pha.pa.us>
0 siblings, 1 reply; 3+ messages in thread
From: Bruce Momjian @ 2002-04-09 03:34 UTC (permalink / raw)
To: Richard Emberson <emberson@phc.net>; +Cc: pgsql-docs
I have added an FAQ item and improved the documentation. Seems the
official current docs aren't being built regularly, (last April 3), so I
pointed to my web copy in the FAQ:
4.25) How do I return multiple rows or columns from a function?
You can return result sets from PL/pgSQL functions using refcursors. See
http://candle.pha.pa.us/main/writings/pgsql/sgml/plpgsql-cursors.html,
section 23.7.3.3.
---------------------------------------------------------------------------
Richard Emberson wrote:
> Thanks for the example. Whoever maintains the documentation ought to put such
> an
> example in the refcursor section.
>
> Richard
>
>
> Bruce Momjian wrote:
>
> > 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@candle.pha.pa.us | (610) 853-3000
> > + If your life is a hard drive, | 830 Blythe Avenue
> > + Christ can be your backup. | Drexel Hill, Pennsylvania 19026
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
>
>
--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: [GENERAL] PL/pgsql return resultset/cursor?
@ 2002-04-09 04:18 Bruce Momjian <pgman@candle.pha.pa.us>
parent: Peter Eisentraut <peter_e@gmx.net>
0 siblings, 0 replies; 3+ messages in thread
From: Bruce Momjian @ 2002-04-09 04:18 UTC (permalink / raw)
To: Peter Eisentraut <peter_e@gmx.net>; +Cc: Richard Emberson <emberson@phc.net>; pgsql-docs
Peter Eisentraut wrote:
> Bruce Momjian writes:
>
> > I have added an FAQ item and improved the documentation. Seems the
> > official current docs aren't being built regularly, (last April 3),
>
> Probably because the markup is temporarily broken.
Oh, is that why. I just fixed it.
> > so I pointed to my web copy in the FAQ:
> >
> > 4.25) How do I return multiple rows or columns from a function?
> >
> > You can return result sets from PL/pgSQL functions using refcursors. See
> > http://candle.pha.pa.us/main/writings/pgsql/sgml/plpgsql-cursors.html,
> > section 23.7.3.3.
>
> Please do not publish links to the development docs.
How do I get around that? I would have to duplicate the doc information
in the FAQ; seems ugly.
--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: [GENERAL] PL/pgsql return resultset/cursor?
@ 2002-04-09 04:18 Peter Eisentraut <peter_e@gmx.net>
parent: Bruce Momjian <pgman@candle.pha.pa.us>
0 siblings, 1 reply; 3+ messages in thread
From: Peter Eisentraut @ 2002-04-09 04:18 UTC (permalink / raw)
To: Bruce Momjian <pgman@candle.pha.pa.us>; +Cc: Richard Emberson <emberson@phc.net>; pgsql-docs
Bruce Momjian writes:
> I have added an FAQ item and improved the documentation. Seems the
> official current docs aren't being built regularly, (last April 3),
Probably because the markup is temporarily broken.
> so I pointed to my web copy in the FAQ:
>
> 4.25) How do I return multiple rows or columns from a function?
>
> You can return result sets from PL/pgSQL functions using refcursors. See
> http://candle.pha.pa.us/main/writings/pgsql/sgml/plpgsql-cursors.html,
> section 23.7.3.3.
Please do not publish links to the development docs.
--
Peter Eisentraut peter_e@gmx.net
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2002-04-09 04:18 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-04-09 03:34 Re: [GENERAL] PL/pgsql return resultset/cursor? Bruce Momjian <pgman@candle.pha.pa.us>
2002-04-09 04:18 ` Peter Eisentraut <peter_e@gmx.net>
2002-04-09 04:18 ` Bruce Momjian <pgman@candle.pha.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox