SQL statement PREPARE does not work in ECPG

From: "Takahashi, Ryohei" <r(dot)takahashi_2(at)jp(dot)fujitsu(dot)com>
To: "'pgsql-hackers(at)postgresql(dot)org'" <pgsql-hackers(at)postgresql(dot)org>
Subject: SQL statement PREPARE does not work in ECPG
Date: 2019-02-19 01:04:46
Message-ID: EE586BE92A4AFB45B03310C2A0C0565D6D37FDFC@G01JPEXMBKW03
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

In the PostgreSQL Documentation, both ECPG PREPARE and SQL statement PREPARE can be used in ECPG [1].
However, SQL statement PREPARE does not work.

I wrote the source code as follows.

<test_app.pgc>
============================
EXEC SQL PREPARE test_prep (int) AS SELECT id from test_table where id = $1;
EXEC SQL EXECUTE test_prep (2);
============================

PostgreSQL 11.2 ECPG produced following code.

<test_app.c>
============================
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "prepare \"test_prep\" ( int ) as \" select id from test_table where id = $1 \"", ECPGt_EOIT, ECPGt_EORT);
#line 16 "test_app.pgc"

if (sqlca.sqlcode < 0) error_exit ( );}
#line 16 "test_app.pgc"

{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "test_prep", ECPGt_EOIT, ECPGt_EORT);
#line 17 "test_app.pgc"

if (sqlca.sqlcode < 0) error_exit ( );}
#line 17 "test_app.pgc"
============================

There are following problems.

(1)
When I run this program, it failed with "PostgreSQL error : -202[too few arguments on line 16]".
The reason is ECPGdo has no argument though prepare statement has "$1".

(2)
I want to execute test_prep (2), but ECPGst_execute does not have argument.

Can SQL statement PREPARE be really used in ECPG?

[1] - https://www.postgresql.org/docs/11/ecpg-sql-prepare.html

Regards,
Ryohei Takahashi

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Matsumura, Ryo 2019-02-19 01:09:32 RE: [PROPOSAL]a new data type 'bytea' for ECPG
Previous Message Amit Langote 2019-02-19 00:54:47 Re: speeding up planning with partitions