Dynamic procedure execution

From: "Muthukumar(dot)GK" <muthankumar(at)gmail(dot)com>
To: "pgsql-general(at)postgresql(dot)org >> PG-General Mailing List" <pgsql-general(at)postgresql(dot)org>
Subject: Dynamic procedure execution
Date: 2020-12-14 05:59:39
Message-ID: CA+rAWg=2VG8N_k5cgCZ3KsWBh4YVRngYbeMGjsfxh=6vmXJW1Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi team,

When I am trying to implement belwo dynamic concept in postgreSql, getting
some error. Kindly find the below attached program and error. Please advise
me what is wrong here..

CREATE OR REPLACE PROCEDURE DynamicProc()

AS $$

DECLARE v_query TEXT;

C1 refcursor := 'result1';

begin

v_query := '';

v_query := ' OPEN C1 FOR SELECT * FROM public."Bankdetails"';

EXECUTE (v_query);

END;

$$

Language plpgsql;

Calling procedure :-

--------------------------------

CALL DynamicProc();

FETCH ALL IN "result1";

Error :-

--------------

ERROR: syntax error at or near "OPEN"

LINE 1: OPEN C1 FOR SELECT * FROM public."Los_BankInfo" ^

QUERY: OPEN C1 FOR SELECT * FROM public."Los_BankInfo"

CONTEXT: PL/pgSQL function dynamicproc() line 9 at EXECUTE SQL state: 42601

Regards

Muthukumar.gk

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2020-12-14 06:13:15 Re: Dynamic procedure execution
Previous Message Huan Ruan 2020-12-13 23:06:28 Re: Potential BRIN Index Corruption