pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Muthukumar.GK <muthankumar@gmail.com>
To: " <pgsql-general@postgresql.org>
Subject: Re: Dynamic procedure execution
Date: Mon, 14 Dec 2020 07:24:55 -0800
Message-ID: <5991c08b-6136-b6a9-4979-50d1b355ecdb@aklaver.com> (raw)
In-Reply-To: <CA+rAWg=2VG8N_k5cgCZ3KsWBh4YVRngYbeMGjsfxh=6vmXJW1Q@mail.gmail.com>
References: <CA+rAWg=2VG8N_k5cgCZ3KsWBh4YVRngYbeMGjsfxh=6vmXJW1Q@mail.gmail.com>

On 12/13/20 9:59 PM, Muthukumar.GK wrote:
> 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

Two things:

1) The error is from a different version of the procedure then the code. 
The table name is different. Can't be sure that this is the only change. 
So can you synchronize your code with the error.

2) Take a look here:

https://www.postgresql.org/docs/12/plpgsql-cursors.html

42.7.2. Opening Cursors

For why OPEN is plpgsql specific and how to use it.

> 
> 
> Regards
> 
> Muthukumar.gk
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com





view thread (11+ messages)  latest in thread

Message-ID: <5991c08b-6136-b6a9-4979-50d1b355ecdb@aklaver.com>
Permalink:  ../5991c08b-6136-b6a9-4979-50d1b355ecdb@aklaver.com/
Also on:    postgresql.org/message-id/5991c08b-6136-b6a9-4979-50d1b355ecdb@aklaver.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, muthankumar@gmail.com
  Subject: Re: Dynamic procedure execution
  In-Reply-To: <5991c08b-6136-b6a9-4979-50d1b355ecdb@aklaver.com>
  References: <CA+rAWg=2VG8N_k5cgCZ3KsWBh4YVRngYbeMGjsfxh=6vmXJW1Q@mail.gmail.com> <5991c08b-6136-b6a9-4979-50d1b355ecdb@aklaver.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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