Send multiple statements to pg server at once

Started by Andy Fan10 months ago3 messages
#1Andy Fan
zhihuifan1213@163.com

Hi,

I want to simulate a case where server receive "SELECT 1;SELECT 2;" at
once, so when executing exec_simple_query, the query_string is
"SELECT 1;SELECT 2;" However I found it is not easy to simulate, does
anyone has a suggestion?

I tried 'psql -f', checking 'psql/settings.h', at last I see below code
in psql/mainloop.c, I guess it is impossible in psql.

/*
* Send command if semicolon found, or if end of line and we're in
* single-line mode.
*/
if (scan_result == PSCAN_SEMICOLON ||
(scan_result == PSCAN_EOL && pset.singleline))
{

--
Best Regards
Andy Fan

#2Pavel Stehule
pavel.stehule@gmail.com
In reply to: Andy Fan (#1)
Re: Send multiple statements to pg server at once

Hi

út 11. 3. 2025 v 8:23 odesílatel Andy Fan <zhihuifan1213@163.com> napsal:

Hi,

I want to simulate a case where server receive "SELECT 1;SELECT 2;" at
once, so when executing exec_simple_query, the query_string is
"SELECT 1;SELECT 2;" However I found it is not easy to simulate, does
anyone has a suggestion?

I tried 'psql -f', checking 'psql/settings.h', at last I see below code
in psql/mainloop.c, I guess it is impossible in psql.

/*
* Send command if semicolon found, or if end of line and we're in
* single-line mode.
*/
if (scan_result == PSCAN_SEMICOLON ||
(scan_result == PSCAN_EOL && pset.singleline))
{

If I remember well, you can use \; for this case

https://www.postgresql.org/docs/current/app-psql.html

Regards

Pavel

Show quoted text

--
Best Regards
Andy Fan

#3Andy Fan
zhihuifan1213@163.com
In reply to: Pavel Stehule (#2)
Re: Send multiple statements to pg server at once

Pavel Stehule <pavel.stehule@gmail.com> writes:

If I remember well, you can use \; for this case

https://www.postgresql.org/docs/current/app-psql.html

Regards

Thank you Pavel, it works! This is so handy!

--
Best Regards
Andy Fan