From 4511717c2eb8d90b467b8585b66cafcc7ef9dc7d Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Tue, 8 Sep 2020 20:03:05 +0200 Subject: [PATCH v3 1/3] psql: Display multiple result sets If a query returns multiple result sets, display all of them instead of only the one that PQexec() returns. Adjust various regression tests to handle the new additional output. --- src/bin/psql/common.c | 25 +++++----- src/test/regress/expected/copyselect.out | 5 ++ src/test/regress/expected/create_table.out | 11 +++-- src/test/regress/expected/psql.out | 6 +-- src/test/regress/expected/sanity_check.out | 1 - src/test/regress/expected/transactions.out | 56 ++++++++++++++++++++++ 6 files changed, 82 insertions(+), 22 deletions(-) diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c index 9a00499510..1be1cf3a8a 100644 --- a/src/bin/psql/common.c +++ b/src/bin/psql/common.c @@ -1300,22 +1300,25 @@ SendQuery(const char *query) if (pset.timing) INSTR_TIME_SET_CURRENT(before); - results = PQexec(pset.db, query); + PQsendQuery(pset.db, query); /* these operations are included in the timing result: */ ResetCancelConn(); - OK = ProcessResult(&results); - - if (pset.timing) + while ((results = PQgetResult(pset.db))) { - INSTR_TIME_SET_CURRENT(after); - INSTR_TIME_SUBTRACT(after, before); - elapsed_msec = INSTR_TIME_GET_MILLISEC(after); - } + OK = ProcessResult(&results); + + if (pset.timing) + { + INSTR_TIME_SET_CURRENT(after); + INSTR_TIME_SUBTRACT(after, before); + elapsed_msec = INSTR_TIME_GET_MILLISEC(after); + } - /* but printing results isn't: */ - if (OK && results) - OK = PrintQueryResults(results); + /* but printing results isn't: */ + if (OK && results) + OK = PrintQueryResults(results); + } } else { diff --git a/src/test/regress/expected/copyselect.out b/src/test/regress/expected/copyselect.out index 72865fe1eb..a13e1b411b 100644 --- a/src/test/regress/expected/copyselect.out +++ b/src/test/regress/expected/copyselect.out @@ -136,6 +136,11 @@ copy (select 1) to stdout\; copy (select 2) to stdout\; select 0\; select 3; -- create table test3 (c int); select 0\; copy test3 from stdin\; copy test3 from stdin\; select 1; -- 1 + ?column? +---------- + 0 +(1 row) + ?column? ---------- 1 diff --git a/src/test/regress/expected/create_table.out b/src/test/regress/expected/create_table.out index ad89dd05c1..17ccce90ee 100644 --- a/src/test/regress/expected/create_table.out +++ b/src/test/regress/expected/create_table.out @@ -279,12 +279,13 @@ DEALLOCATE select1; -- (temporarily hide query, to avoid the long CREATE TABLE stmt) \set ECHO none INSERT INTO extra_wide_table(firstc, lastc) VALUES('first col', 'last col'); +ERROR: relation "extra_wide_table" does not exist +LINE 1: INSERT INTO extra_wide_table(firstc, lastc) VALUES('first co... + ^ SELECT firstc, lastc FROM extra_wide_table; - firstc | lastc ------------+---------- - first col | last col -(1 row) - +ERROR: relation "extra_wide_table" does not exist +LINE 1: SELECT firstc, lastc FROM extra_wide_table; + ^ -- check that tables with oids cannot be created anymore CREATE TABLE withoid() WITH OIDS; ERROR: syntax error at or near "OIDS" diff --git a/src/test/regress/expected/psql.out b/src/test/regress/expected/psql.out index 1b2f6bc418..c7f5891c40 100644 --- a/src/test/regress/expected/psql.out +++ b/src/test/regress/expected/psql.out @@ -258,11 +258,7 @@ union all select 'drop table gexec_test', 'select ''2000-01-01''::date as party_over' \gexec select 1 as ones - ones ------- - 1 -(1 row) - +ERROR: DECLARE CURSOR can only be used in transaction blocks select x.y, x.y*2 as double from generate_series(1,4) as x(y) y | double ---+-------- diff --git a/src/test/regress/expected/sanity_check.out b/src/test/regress/expected/sanity_check.out index d9ce961be2..bd3f1be90c 100644 --- a/src/test/regress/expected/sanity_check.out +++ b/src/test/regress/expected/sanity_check.out @@ -43,7 +43,6 @@ dupindexcols|t e_star|f emp|f equipment_r|f -extra_wide_table|f f_star|f fast_emp4000|t float4_tbl|f diff --git a/src/test/regress/expected/transactions.out b/src/test/regress/expected/transactions.out index 61862d595d..d22027cb86 100644 --- a/src/test/regress/expected/transactions.out +++ b/src/test/regress/expected/transactions.out @@ -902,6 +902,16 @@ DROP TABLE abc; create temp table i_table (f1 int); -- psql will show only the last result in a multi-statement Query SELECT 1\; SELECT 2\; SELECT 3; + ?column? +---------- + 1 +(1 row) + + ?column? +---------- + 2 +(1 row) + ?column? ---------- 3 @@ -916,6 +926,12 @@ insert into i_table values(1)\; select * from i_table; -- 1/0 error will cause rolling back the whole implicit transaction insert into i_table values(2)\; select * from i_table\; select 1/0; + f1 +---- + 1 + 2 +(2 rows) + ERROR: division by zero select * from i_table; f1 @@ -935,8 +951,18 @@ WARNING: there is no transaction in progress -- begin converts implicit transaction into a regular one that -- can extend past the end of the Query select 1\; begin\; insert into i_table values(5); + ?column? +---------- + 1 +(1 row) + commit; select 1\; begin\; insert into i_table values(6); + ?column? +---------- + 1 +(1 row) + rollback; -- commit in implicit-transaction state commits but issues a warning. insert into i_table values(7)\; commit\; insert into i_table values(8)\; select 1/0; @@ -963,22 +989,52 @@ rollback; -- we are not in a transaction at this point WARNING: there is no transaction in progress -- implicit transaction block is still a transaction block, for e.g. VACUUM SELECT 1\; VACUUM; + ?column? +---------- + 1 +(1 row) + ERROR: VACUUM cannot run inside a transaction block SELECT 1\; COMMIT\; VACUUM; WARNING: there is no transaction in progress + ?column? +---------- + 1 +(1 row) + ERROR: VACUUM cannot run inside a transaction block -- we disallow savepoint-related commands in implicit-transaction state SELECT 1\; SAVEPOINT sp; + ?column? +---------- + 1 +(1 row) + ERROR: SAVEPOINT can only be used in transaction blocks SELECT 1\; COMMIT\; SAVEPOINT sp; WARNING: there is no transaction in progress + ?column? +---------- + 1 +(1 row) + ERROR: SAVEPOINT can only be used in transaction blocks ROLLBACK TO SAVEPOINT sp\; SELECT 2; ERROR: ROLLBACK TO SAVEPOINT can only be used in transaction blocks SELECT 2\; RELEASE SAVEPOINT sp\; SELECT 3; + ?column? +---------- + 2 +(1 row) + ERROR: RELEASE SAVEPOINT can only be used in transaction blocks -- but this is OK, because the BEGIN converts it to a regular xact SELECT 1\; BEGIN\; SAVEPOINT sp\; ROLLBACK TO SAVEPOINT sp\; COMMIT; + ?column? +---------- + 1 +(1 row) + -- Tests for AND CHAIN in implicit transaction blocks SET TRANSACTION READ ONLY\; COMMIT AND CHAIN; -- error ERROR: COMMIT AND CHAIN can only be used in transaction blocks -- 2.32.0