ecpg command does not warn COPY ... FROM STDIN;

From: Ryo Kanbayashi <kanbayashi(dot)dev(at)gmail(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: ecpg command does not warn COPY ... FROM STDIN;
Date: 2025-01-08 12:41:03
Message-ID: CANOn0Ez_t5uDCUEV8c1YORMisJiU5wu681eEVZzgKwOeiKhkqQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi hackers,

I found a code validation bug in master branch.

Now, ecpg does not support 'EXEC SQL COPY ... FROM STDIN ... ;' and
code for warning it exits.

https://github.com/postgres/postgres/blob/7b27f5fd36cb3270e8ac25aefd73b552663d1392/src/interfaces/ecpg/preproc/ecpg.addons#L242-L245
---
ECPG: addon CopyStmt COPY opt_binary qualified_name opt_column_list
copy_from opt_program copy_file_name copy_delimiter opt_with
copy_options where_clause
if (strcmp(@6, "from") == 0 &&
(strcmp(@7, "stdin") == 0 || strcmp(@7, "stdout") == 0))
mmerror(PARSE_ERROR, ET_WARNING, "COPY FROM STDIN is not implemented");
---

But it is not working.
ecpg command fails to notice though code like above exits on pgc code.

# COPY ... FROM STDIN code
ryo(at)DESKTOP-IOASPN6:~/work/postgres/src$ cat copy_from_should_be_warned.pgc
#include <stdio.h>
#include <stdlib.h>

EXEC SQL WHENEVER SQLERROR CALL die();
EXEC SQL WHENEVER NOT FOUND DO BREAK;

void
die(void)
{
fprintf(stderr, "%s\n", sqlca.sqlerrm.sqlerrmc);
exit(1);
}

int
main(void)
{
EXEC SQL BEGIN DECLARE SECTION;
const char *target = "postgres(at)localhost:5432";
const char *user = "ryo";
const char *passwd = "";
EXEC SQL END DECLARE SECTION;

EXEC SQL CONNECT TO :target USER :user USING :passwd;
EXEC SQL COPY name_age_list FROM STDIN;
EXEC SQL COMMIT;
EXEC SQL DISCONNECT ALL;

return 0;
}
-----

I executed ecpg command for above code.

ryo(at)DESKTOP-IOASPN6:~/work/postgres/src$ ../master/bin/ecpg
copy_from_should_be_warned.pgc
ryo(at)DESKTOP-IOASPN6:~/work/postgres/src$

But there was no warning and generaged c source.

So, I wrote patch.
the patch changes @6 on code above to @5.
Checked variable was wrong.

After apply patch, warning is shown.
(c source is generated as before)

ryo(at)DESKTOP-IOASPN6:~/work/postgres/src$ ../master/bin/ecpg
copy_from_should_be_warned.pgc
copy_from_should_be_warned.pgc:24: WARNING: COPY FROM STDIN is not implemented
ryo(at)DESKTOP-IOASPN6:~/work/postgres/src$

--
Best regards,
Ryo Kanbayashi
kanbayashi(dot)dev(at)gmail(dot)com
https://github.com/ryogrid

Attachment Content-Type Size
patch_checking_note.txt text/plain 8.1 KB
copy_from_ok.pgc application/octet-stream 610 bytes
copy_from_should_be_warned.pgc application/octet-stream 576 bytes
copy_from_stdin_no_warning.patch application/octet-stream 851 bytes

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jakub Wartak 2025-01-08 12:49:38 Re: doc: Mention clock synchronization recommendation for hot_standby_feedback
Previous Message Rahila Syed 2025-01-08 12:03:01 Re: Enhancing Memory Context Statistics Reporting