Thread: double counting of lines in psql

double counting of lines in psql

From
Andrew Dunstan
Date:
This tiny change fixes what I think is a longstanding bug in psql. I 
causes the first line of every cell to be counted twice, whereas it 
should in fact be excluded from extra_lines / extra_row_output_lines. 
The bug appears to date back to commit 43ee2282 in 2008. Changing it 
appears to make my proposed pager_min_lines feature work as expected.

So, should it be backpatched? It's a behaviour change, albeit that the 
existing behaviour is a bug, and will cause the pager to be invoked on 
output that is way too short (by about half a screen's height, I think).

cheers

andrew



diff --git a/src/bin/psql/print.c b/src/bin/psql/print.c
index 2e158b8..c93f744 100644
--- a/src/bin/psql/print.c
+++ b/src/bin/psql/print.c
@@ -837,7 +837,7 @@ print_aligned_text(const printTableContent *cont, 
FILE *fout)            {                unsigned int extra_lines;

-               extra_lines = (width - 1) / width_wrap[i] + nl_lines;
+               extra_lines = ((width - 1) / width_wrap[i]) + (nl_lines 
- 1);                if (extra_lines > extra_row_output_lines)                    extra_row_output_lines = extra_lines;
          }
 





Re: double counting of lines in psql

From
David Fetter
Date:
On Mon, Nov 17, 2014 at 11:13:15AM -0500, Andrew Dunstan wrote:
> 
> This tiny change fixes what I think is a longstanding bug in psql. I causes
> the first line of every cell to be counted twice, whereas it should in fact
> be excluded from extra_lines / extra_row_output_lines. The bug appears to
> date back to commit 43ee2282 in 2008. Changing it appears to make my
> proposed pager_min_lines feature work as expected.
> 
> So, should it be backpatched? It's a behaviour change, albeit that the
> existing behaviour is a bug, and will cause the pager to be invoked on
> output that is way too short (by about half a screen's height, I think).

+1 

It's a bug fix that changes behavior no reasonable script could count on.

Cheers,
David.
-- 
David Fetter <david@fetter.org> http://fetter.org/
Phone: +1 415 235 3778  AIM: dfetter666  Yahoo!: dfetter
Skype: davidfetter      XMPP: david.fetter@gmail.com

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate



Re: double counting of lines in psql

From
Andrew Dunstan
Date:
On 11/18/2014 10:43 AM, David Fetter wrote:
> On Mon, Nov 17, 2014 at 11:13:15AM -0500, Andrew Dunstan wrote:
>> This tiny change fixes what I think is a longstanding bug in psql. I causes
>> the first line of every cell to be counted twice, whereas it should in fact
>> be excluded from extra_lines / extra_row_output_lines. The bug appears to
>> date back to commit 43ee2282 in 2008. Changing it appears to make my
>> proposed pager_min_lines feature work as expected.
>>
>> So, should it be backpatched? It's a behaviour change, albeit that the
>> existing behaviour is a bug, and will cause the pager to be invoked on
>> output that is way too short (by about half a screen's height, I think).
> +1
>
> It's a bug fix that changes behavior no reasonable script could count on.
>

Actually, I think I'm coming down on the side of not changing it in the 
back branches. As Andres noted elsewhere, you can overcome most of the 
bad effects of this by using the less pager with the -F option.

cheers

andrew