Re: Dynamic SQL in Function

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: rwade(at)uci(dot)edu
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Dynamic SQL in Function
Date: 2009-04-22 18:54:44
Message-ID: b42b73150904221154j6c623ea9lf9eb6efbd7d10295@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Apr 22, 2009 at 12:29 PM, <rwade(at)uci(dot)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;

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Thomas Kellerer 2009-04-22 18:54:48 Re: Error installing Postgres
Previous Message Thomas Kellerer 2009-04-22 18:54:00 Re: Error installing Postgres