Re: [INTERFACES] ecpg: why use PREPARE?

From: Michael Meskes <meskes(at)postgresql(dot)org>
To: "UEBAYASHI 'UMA' Masao" <masao(at)nf(dot)enveng(dot)titech(dot)ac(dot)jp>
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: [INTERFACES] ecpg: why use PREPARE?
Date: 1999-12-02 13:05:05
Message-ID: 19991202140505.A2305@fam-meskes.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

On Thu, Dec 02, 1999 at 07:14:28PM +0900, UEBAYASHI 'UMA' Masao wrote:
> example programs. I can see such lines like below in test2.pgc:
> ...
> As far, I know the differences between the normal one and the parepare

As the comment says:

/* and now the same query with prepare */

This example is just to check ecpg's functionality and to show that it is
possible to use prepare.

> one are that the prepare one:
>
> 1) prepares statement `MM' and creates cursor on it.
> 2) opens the cursor with ``using''
>
> I have no idea what these mean. My test program which is simply
> changed from ``declare cursor'' to ``prepare + declare'' seems to run
> the same way and takes the same time.

That's what supposed to happen. PREPARE is used for so-called dynamic SQL.
Just imagine a query where a variable in the where clause changes depending
on the flow of a program. Then you can either use two different cursors with
quite some work needed doubling program logic or you used give the prepared
statement the other variable via the using clause.

Or thing about an SQL statement that is dynamically created during run time.
You cannot use this without preparing it.

Hope this helps.

Michael
--
Michael Meskes | Go SF 49ers!
Th.-Heuss-Str. 61, D-41812 Erkelenz | Go Rhein Fire!
Tel.: (+49) 2431/72651 | Use Debian GNU/Linux!
Email: Michael(at)Fam-Meskes(dot)De | Use PostgreSQL!

In response to

Browse pgsql-interfaces by date

  From Date Subject
Next Message Tom Lane 1999-12-02 15:21:43 Re: [INTERFACES] Slow join query optimisation?
Previous Message Jeroen Schellart 1999-12-02 11:59:00 subscribe