Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old November 23rd, 2005, 12:26 AM
Rajat Katyal
Guest
 
Posts: n/a
Default Problem in calling prepare statement from STORED PROCEDURE

Hi:

I prepare the statement for execution as follows:

PREPARE query(text) as SELECT count(*) FROM transform_customer_billing where inv_no = $1;

The problem is Iam not able to execute this prepare statement from the stored procedure defined. I added the statement to call the prepare statement is: EXECUTE query('100023'). The ERROR it prints : Function query(text) doesnot exist.

Please suggest the solution for this problem.

Thanks in advance.

Rajat

  #2  
Old November 23rd, 2005, 12:26 AM
Rajesh Kumar Mallah
Guest
 
Posts: n/a
Default Re: Problem in calling prepare statement from STORED PROCEDURE



Hi,

Inside a stored procedure EXECUTE runs a dynamic query,


DOCS SAY:

Oftentimes you will want to generate dynamic commands inside your
PL/pgSQL functions, that is, commands that will involve different tables
or different data types each time they are executed. PL/pgSQL's normal
attempts to cache plans for commands will not work in such scenarios. To
handle this sort of problem, the EXECUTE statement is provided:

EXECUTE command-string;

where command-string is an expression yielding a string (of type text)
containing the command to be executed. This string is fed literally to
the SQL engine.


Really not sure how to execute a named plan inside plpgsql.

Regds
mallah.



Rajat Katyal wrote:
[color=blue]
> Hi:
>
> I prepare the statement for execution as follows:
>
> *PREPARE query(text) as SELECT count(*) FROM
> transform_customer_billing where inv_no = $1;*
> **
> The problem is Iam not able to execute this prepare statement from
> the stored procedure defined. I added the statement to call the
> prepare statement is: *EXECUTE query('100023'). *The ERROR it prints :
> *Function query(text) does not exist.*
>
> Please suggest the solution for this problem.
>
> Thanks in advance.
>
> Rajat[/color]



  #3  
Old November 23rd, 2005, 12:26 AM
Tom Lane
Guest
 
Posts: n/a
Default Re: Problem in calling prepare statement from STORED PROCEDURE

"Rajat Katyal" <rajatk@intelesoftech.com> writes:[color=blue]
> I prepare the statement for execution as follows:
> PREPARE query(text) as SELECT count(*) FROM transform_customer_billing wher=
> e inv_no =3D $1;
> The problem is Iam not able to execute this prepare statement from the stor=
> ed procedure defined.[/color]

EXECUTE means something different in plpgsql than it does in plain SQL,
and you do not need PREPARE at all in plpgsql. plpgsql's automatic
caching of plans gives you the effect of PREPARE on every statement
without your having to ask for it.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles