Re: BUG #18134: ROW_COUNT do not set to 0 when psql's \gset command get no rows returned

Поиск
Список
Период
Сортировка
От Japin Li
Тема Re: BUG #18134: ROW_COUNT do not set to 0 when psql's \gset command get no rows returned
Дата
Msg-id MEYP282MB1669351F137C61C19FA9749BB6C2A@MEYP282MB1669.AUSP282.PROD.OUTLOOK.COM
обсуждение исходный текст
Ответ на BUG #18134: ROW_COUNT do not set to 0 when psql's \gset command get no rows returned  (PG Bug reporting form <noreply@postgresql.org>)
Ответы Re: BUG #18134: ROW_COUNT do not set to 0 when psql's \gset command get no rows returned  (Jov <amutu@amutu.com>)
Re: BUG #18134: ROW_COUNT do not set to 0 when psql's \gset command get no rows returned  (Michael Paquier <michael@paquier.xyz>)
Список pgsql-bugs
On Tue, 26 Sep 2023 at 09:26, PG Bug reporting form <noreply@postgresql.org> wrote:
> The following bug has been logged on the website:
>
> Bug reference:      18134
> Logged by:          amutu
> Email address:      amutu@amutu.com
> PostgreSQL version: 15.4
> Operating system:   FreeBSD 13.2-RELEASE amd64
> Description:
>
> reproduce steps:
>
> $psql postgres
> psql (15.4)
> Type "help" for help.
>
> postgres=# select * from cmdq  where status= 'new' \gset
> no rows returned for \gset
> postgres=# \echo :ROW_COUNT
> :ROW_COUNT
> postgres=# select * from cmdq;
>    cmd   |  src_ip   | worker | status |              ts               | id
>
> ---------+-----------+--------+--------+-------------------------------+----
>  ls /tmp | 127.0.0.1 |        | done   | 2023-09-23 14:39:59.047309+08 |
> 1
> (1 row)
>
> postgres=# \echo :ROW_COUNT
> 1
> postgres=# select * from cmdq  where status= 'new' \gset
> no rows returned for \gset
> postgres=# \echo :ROW_COUNT
> 1
> ------------------------------------------------
> from the psql doc:
> ROW_COUNT
> The number of rows returned or affected by the last SQL query, !!!!or 0 if
> the query failed or did not report a row count.!!!!

It seems SaveResultVariables() was lost when executing failed. Attached fix it.

diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c
index ede197bebe..cf6c7778ee 100644
--- a/src/bin/psql/common.c
+++ b/src/bin/psql/common.c
@@ -1660,8 +1660,8 @@ ExecQueryAndProcessResults(const char *query,
         }
 
         /* set variables on last result if all went well */
-        if (!is_watch && last && success)
-            SetResultVariables(result, true);
+        if (!is_watch && last)
+            SetResultVariables(result, success);
 
         ClearOrSaveResult(result);
         result = next_result;

-- 
Regrads,
Japin Li
ChengDu WenWu Information Technology Co., Ltd.


В списке pgsql-bugs по дате отправления:

Предыдущее
От: PG Bug reporting form
Дата:
Сообщение: BUG #18135: Incorrect memory access occurs when attaching a partition with an index
Следующее
От: Japin Li
Дата:
Сообщение: Re: Bug of psql meta-command \sf & \sv