pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedecpg: why use PREPARE?
2+ messages / 2 participants
[nested] [flat]
* ecpg: why use PREPARE?
@ 1999-12-02 10:14 UEBAYASHI 'UMA' Masao <masao@nf.enveng.titech.ac.jp>
0 siblings, 1 reply; 2+ messages in thread
From: UEBAYASHI 'UMA' Masao @ 1999-12-02 10:14 UTC (permalink / raw)
To: pgsql-interfaces
I'm new to both PostgreSQL and ecpg (Embedded SQL), and examinig ecpg
example programs. I can see such lines like below in test2.pgc:
| ...
| /* normal version */
| exec sql open cur;
| exec sql whenever not found do break;
| while (1) {
| exec sql fetch in cur into :personal:ind_personal, :married:ind_married, :children.integer:ind_children.smallint;
| ...
| }
| exec sql close cur;
| ...
| ...
| /* prepare version */
| exec sql prepare MM from :query;
| exec sql declare prep cursor for MM;
| exec sql open prep using :testname;
| exec sql whenever not found do break;
| while (1) {
| exec sql fetch in prep into :personal:ind_personal, :married:ind_married, :children.integer:ind_children.smallint;
| ...
| }
| ...
As far, I know the differences between the normal one and the parepare
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.
Any help will be appreciated. :)
Masao
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: [INTERFACES] ecpg: why use PREPARE?
@ 1999-12-02 13:05 Michael Meskes <meskes@postgresql.org>
parent: UEBAYASHI 'UMA' Masao <masao@nf.enveng.titech.ac.jp>
0 siblings, 0 replies; 2+ messages in thread
From: Michael Meskes @ 1999-12-02 13:05 UTC (permalink / raw)
To: UEBAYASHI 'UMA' Masao <masao@nf.enveng.titech.ac.jp>; +Cc: 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@Fam-Meskes.De | Use PostgreSQL!
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~1999-12-02 13:05 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-12-02 10:14 ecpg: why use PREPARE? UEBAYASHI 'UMA' Masao <masao@nf.enveng.titech.ac.jp>
1999-12-02 13:05 ` Michael Meskes <meskes@postgresql.org>
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