ECPG: inconsistent behavior with the document in “GET/SET DESCRIPTOR.”

From: "Masashi Kamura (Fujitsu)" <kamura(dot)masashi(at)fujitsu(dot)com>
To: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: ECPG: inconsistent behavior with the document in “GET/SET DESCRIPTOR.”
Date: 2026-03-11 09:49:46
Message-ID: OS9PR01MB13174AD7D1829D0644B6BB90E9447A@OS9PR01MB13174.jpnprd01.prod.outlook.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

While using ECPG and its SQL descriptor, I found an inconsistency
between the document and the actual behavior.

According to the manual, it states that multiple header items can be specified.
https://www.postgresql.org/docs/current/ecpg-sql-get-descriptor.html
```
GET DESCRIPTOR descriptor_name :cvariable = descriptor_header_item [, ... ]
GET DESCRIPTOR descriptor_name VALUE column_number :cvariable = descriptor_item [, ... ]
```

So following embedded SQL should be accepted.
Actually, the compiler says OK.
However, the output source cannot be compiled.

Embedded SQL:
```
EXEC SQL GET DESCRIPTOR d :desc_count1 = count, :desc_count2 = count; 
```

Precompiled result:
```
{ ECPGget_desc_header(__LINE__, "d", &(desc_count2desc_count1)); 
```

Reported error by the compiler:
```
bytea.pgc: In function 'main': 

bytea.pgc:123:48: error: 'desc_count2desc_count1' undeclared (first use in this function) 

 123 |     exec sql get descriptor d :desc_count1 = count, :desc_count2 = count; 

   |                        ^~~~~~~~~~~~~~~~~~~~~~ 

bytea.pgc:123:48: note: each undeclared identifier is reported only once for each function it appears in
```

According to my analysis, the parser can accept multiple headers,
but the output function cannot.
See ECPGGetDescHeaderItems and output_get_descr_header().
Therefore, it is thought that the variables were incorrectly concatenated,
resulting in an error.

I feel even if multiple header items cannot be specified,
invalid syntax should be detected by the precompiler, not the compiler.
Attached patch fixes both parser and the documentation.
After applying the patch, the above example can detect the invalid syntax
by the precompiler anymore.
```
bytea.pgc:123: ERROR: syntax error at or near ","
```

SET DESCRIPTOR also has the same issue, thus the patch fixes both.

I'm looking forward to your comments.

Regards,
Masashi Kamura
Fujitsu Limited

Attachment Content-Type Size
0001-ECPG-Reject-multiple-headers-in-GET-SET-DESCRIPTOR-a.patch application/octet-stream 3.2 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Shin Berg 2026-03-11 09:54:01 Re: Inconsistency in owner assignment between INDEX and STATISTICS
Previous Message Shiju Sivadazz 2026-03-11 09:45:28 Question about heap_inplace_update and VACUUM behavior