Re: Dynamic SQL in Function - Mailing list pgsql-general

From Merlin Moncure
Subject Re: Dynamic SQL in Function
Date
Msg-id b42b73150904221154j6c623ea9lf9eb6efbd7d10295@mail.gmail.com
Whole thread Raw
In response to Dynamic SQL in Function  (rwade@uci.edu)
Responses Re: Dynamic SQL in Function
Re: Dynamic SQL in Function
List pgsql-general
On Wed, Apr 22, 2009 at 12:29 PM,  <rwade@uci.edu> wrote:
> If I have built a dynamic sql statement in a function, how do i return it
> as a ref cursor?

CREATE FUNCTION reffunc(_ref) RETURNS refcursor AS
$$
BEGIN
    OPEN _ref FOR execute 'SELECT * from foo';
    RETURN _ref;
END;
$$ LANGUAGE plpgsql;

BEGIN;
SELECT reffunc('funccursor');
FETCH ALL IN funccursor;
COMMIT;

pgsql-general by date:

Previous
From: Thomas Kellerer
Date:
Subject: Re: Error installing Postgres
Next
From: Thomas Kellerer
Date:
Subject: Re: Error installing Postgres