Fix \watch if expanded output is on and there are no results

From: Michael Banck <michael(dot)banck(at)credativ(dot)de>
To: PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org>
Subject: Fix \watch if expanded output is on and there are no results
Date: 2021-01-09 15:40:59
Message-ID: e72b9c3b052675e940697012932fe897b73806d8.camel@credativ.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

in expanded output, psql does not print the title if there are zero
results. In regular output, it prints the title ("foo") no matter how
many rows:

postgres=# \pset title foo
Title is "foo".
postgres=# SELECT 1 WHERE 1=1;
foo
?column?
----------
1
(1 row)

postgres=# SELECT 1 WHERE 1=2;
foo
?column?
----------
(0 rows)

In expanded mode, it only prints the title if there is at least one row:

postgres=# \x
Expanded display is on.
postgres=# SELECT 1 WHERE 1=1;
foo
-[ RECORD 1 ]
?column? | 1

postgres=# SELECT 1 WHERE 1=2;
(0 rows)

Is that intentional? It breaks \watch for expanded output if the query
being watched does not always return at least one row. If that is not
the case, the timestamp is ommitted. I think that's bad enough to
warrant fixing like in the attached.

But maybe there was a good reason the title wasn't printed? On the ohter
hand, we're just returning early from print_aligned_vertical() right now
and never get to the part where we usually print the title if there are
zero results.

Michael

--
Michael Banck
Projektleiter / Senior Berater
Tel.: +49 2166 9901-171
Fax: +49 2166 9901-100
Email: michael(dot)banck(at)credativ(dot)de

credativ GmbH, HRB Mönchengladbach 12080
USt-ID-Nummer: DE204566209
Trompeterallee 108, 41189 Mönchengladbach
Geschäftsführung: Dr. Michael Meskes, Jörg Folz, Sascha Heuer

Unser Umgang mit personenbezogenen Daten unterliegt
folgenden Bestimmungen: https://www.credativ.de/datenschutz

Attachment Content-Type Size
fix_expanded_output_title_no_rows.patch text/x-patch 422 bytes

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2021-01-09 18:17:36 Re: Key management with tests
Previous Message Zhihong Yu 2021-01-09 15:29:11 Re: Implement <null treatment> for window functions