patch: psql - enforce constant width of last column

Lists: pgsql-hackers
From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: patch: psql - enforce constant width of last column
Date: 2019-09-09 09:25:32
Message-ID: CAFj8pRB-m4dCLmsM+7HdMaq5OAnS2h50g16tj1dNG9fYQLyQVw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

Hi

When I played with vertical cursor support I got badly displayed last
columns when border was not 2. Only when border is 2, then psql displays
last column with same width for each row.

I think so we can force column width alignment for any border styles today
(for alignment and wrapping styles) or as minimum this behave can be
optional.

I wrote a patch with pset option "final_spaces", but I don't see a reason
why we trim rows today.

Regards

Pavel

Attachment Content-Type Size
psql-use-final-spaces-always.patch text/x-patch 6.3 KB

From: Ahsan Hadi <ahsan(dot)hadi(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: patch: psql - enforce constant width of last column
Date: 2019-09-17 15:06:09
Message-ID: CA+9bhCKY1csVb_s7TJYbgPu-HhfNH5wfC0QsQO6DNOsmoWx88g@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

Hi Pavel,

I have been trying to reproduce the case of badly displaying last columns
of a query result-set. I played around with the legal values for psql
border variable but not able to find a case where last columns are badly
displayed. Can you please share an example that I can use to reproduce this
problem. I will try out your patch once I am able to reproduce the problem.

Thanks,

-- Ahsan

On Mon, Sep 9, 2019 at 2:32 PM Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
wrote:

> Hi
>
> When I played with vertical cursor support I got badly displayed last
> columns when border was not 2. Only when border is 2, then psql displays
> last column with same width for each row.
>
> I think so we can force column width alignment for any border styles today
> (for alignment and wrapping styles) or as minimum this behave can be
> optional.
>
> I wrote a patch with pset option "final_spaces", but I don't see a reason
> why we trim rows today.
>
> Regards
>
> Pavel
>


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Ahsan Hadi <ahsan(dot)hadi(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: patch: psql - enforce constant width of last column
Date: 2019-09-17 15:15:42
Message-ID: CAFj8pRB+5prxjXyPKMbPPzGwk87ziCewB+ijeJT+3HLPp3xWsw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

út 17. 9. 2019 v 17:06 odesílatel Ahsan Hadi <ahsan(dot)hadi(at)gmail(dot)com> napsal:

> Hi Pavel,
>
> I have been trying to reproduce the case of badly displaying last columns
> of a query result-set. I played around with the legal values for psql
> border variable but not able to find a case where last columns are badly
> displayed. Can you please share an example that I can use to reproduce this
> problem. I will try out your patch once I am able to reproduce the problem.
>

you need to use pspg, and vertical cursor.

https://github.com/okbob/pspg
vertical cursor should be active

\pset border 1
\pset linestyle ascii
\pset pager always

select * from generate_series(1,3);

Regards

Pavel

> Thanks,
>
> -- Ahsan
>
>
> On Mon, Sep 9, 2019 at 2:32 PM Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> wrote:
>
>> Hi
>>
>> When I played with vertical cursor support I got badly displayed last
>> columns when border was not 2. Only when border is 2, then psql displays
>> last column with same width for each row.
>>
>> I think so we can force column width alignment for any border styles
>> today (for alignment and wrapping styles) or as minimum this behave can be
>> optional.
>>
>> I wrote a patch with pset option "final_spaces", but I don't see a reason
>> why we trim rows today.
>>
>> Regards
>>
>> Pavel
>>
>

Attachment Content-Type Size
image/png 19.4 KB

From: Ahsan Hadi <ahsan(dot)hadi(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: patch: psql - enforce constant width of last column
Date: 2019-09-18 10:52:25
Message-ID: CA+9bhCKBe=H5y0wiTQ4rhoAnQOwZGrM99eZPFHQ8ubHNo5ieWg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Sep 17, 2019 at 8:16 PM Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
wrote:

>
>
> út 17. 9. 2019 v 17:06 odesílatel Ahsan Hadi <ahsan(dot)hadi(at)gmail(dot)com>
> napsal:
>
>> Hi Pavel,
>>
>> I have been trying to reproduce the case of badly displaying last columns
>> of a query result-set. I played around with the legal values for psql
>> border variable but not able to find a case where last columns are badly
>> displayed. Can you please share an example that I can use to reproduce this
>> problem. I will try out your patch once I am able to reproduce the problem.
>>
>
> you need to use pspg, and vertical cursor.
>
> https://github.com/okbob/pspg
> vertical cursor should be active
>

okay thanks for the info. I don't think it was possible to figure this out
by reading the initial post. I will check it out.

does this patch have any value for psql without pspg?

> \pset border 1
> \pset linestyle ascii
> \pset pager always
>
> select * from generate_series(1,3);
>
> Regards
>
> Pavel
>
>
>> Thanks,
>>
>> -- Ahsan
>>
>>
>> On Mon, Sep 9, 2019 at 2:32 PM Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
>> wrote:
>>
>>> Hi
>>>
>>> When I played with vertical cursor support I got badly displayed last
>>> columns when border was not 2. Only when border is 2, then psql displays
>>> last column with same width for each row.
>>>
>>> I think so we can force column width alignment for any border styles
>>> today (for alignment and wrapping styles) or as minimum this behave can be
>>> optional.
>>>
>>> I wrote a patch with pset option "final_spaces", but I don't see a
>>> reason why we trim rows today.
>>>
>>> Regards
>>>
>>> Pavel
>>>
>>


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Ahsan Hadi <ahsan(dot)hadi(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: patch: psql - enforce constant width of last column
Date: 2019-09-18 12:51:09
Message-ID: CAFj8pRBnLecoLhcGOF5xnVqEmdJYCNXRdZWXm3erpx61o2podg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

st 18. 9. 2019 v 12:52 odesílatel Ahsan Hadi <ahsan(dot)hadi(at)gmail(dot)com> napsal:

>
>
> On Tue, Sep 17, 2019 at 8:16 PM Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> wrote:
>
>>
>>
>> út 17. 9. 2019 v 17:06 odesílatel Ahsan Hadi <ahsan(dot)hadi(at)gmail(dot)com>
>> napsal:
>>
>>> Hi Pavel,
>>>
>>> I have been trying to reproduce the case of badly displaying last
>>> columns of a query result-set. I played around with the legal values for
>>> psql border variable but not able to find a case where last columns are
>>> badly displayed. Can you please share an example that I can use to
>>> reproduce this problem. I will try out your patch once I am able to
>>> reproduce the problem.
>>>
>>
>> you need to use pspg, and vertical cursor.
>>
>> https://github.com/okbob/pspg
>> vertical cursor should be active
>>
>
> okay thanks for the info. I don't think it was possible to figure this out
> by reading the initial post. I will check it out.
>
> does this patch have any value for psql without pspg?
>

The benefit of this patch is just for pspg users today.

Pavel

>
>> \pset border 1
>> \pset linestyle ascii
>> \pset pager always
>>
>> select * from generate_series(1,3);
>>
>> Regards
>>
>> Pavel
>>
>>
>>> Thanks,
>>>
>>> -- Ahsan
>>>
>>>
>>> On Mon, Sep 9, 2019 at 2:32 PM Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
>>> wrote:
>>>
>>>> Hi
>>>>
>>>> When I played with vertical cursor support I got badly displayed last
>>>> columns when border was not 2. Only when border is 2, then psql displays
>>>> last column with same width for each row.
>>>>
>>>> I think so we can force column width alignment for any border styles
>>>> today (for alignment and wrapping styles) or as minimum this behave can be
>>>> optional.
>>>>
>>>> I wrote a patch with pset option "final_spaces", but I don't see a
>>>> reason why we trim rows today.
>>>>
>>>> Regards
>>>>
>>>> Pavel
>>>>
>>>


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Ahsan Hadi <ahsan(dot)hadi(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: patch: psql - enforce constant width of last column
Date: 2019-09-27 17:47:33
Message-ID: [email protected]
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Sep 17, 2019 at 05:15:42PM +0200, Pavel Stehule wrote:
>
>
> út 17. 9. 2019 v 17:06 odesílatel Ahsan Hadi <ahsan(dot)hadi(at)gmail(dot)com> napsal:
>
> Hi Pavel,
>
> I have been trying to reproduce the case of badly displaying last columns
> of a query result-set. I played around with the legal values for psql
> border variable but not able to find a case where last columns are badly
> displayed. Can you please share an example that I can use to reproduce this
> problem. I will try out your patch once I am able to reproduce the problem.
>
>
> you need to use pspg, and vertical cursor.
>
> https://github.com/okbob/pspg
> vertical cursor should be active
>
> \pset border 1
> \pset linestyle ascii
> \pset pager always
>
> select * from generate_series(1,3);

I was able to reproduce the failure, but with a little more work:

$ export PSQL_PAGER='pspg --vertical-cursor'
$ psql test
\pset border 1
\pset linestyle ascii
\pset pager always
select * from generate_series(1,3);

Line '1' has highlighted trailing space.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ As you are, so once was I. As I am, so you will be. +
+ Ancient Roman grave inscription +


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Ahsan Hadi <ahsan(dot)hadi(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: patch: psql - enforce constant width of last column
Date: 2019-11-04 20:55:46
Message-ID: [email protected]
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> writes:
> st 18. 9. 2019 v 12:52 odesílatel Ahsan Hadi <ahsan(dot)hadi(at)gmail(dot)com> napsal:
>> does this patch have any value for psql without pspg?

> The benefit of this patch is just for pspg users today.

TBH, I think we should just reject this patch. It makes psql's
table-printing behavior even more complicated than it was before.
And I don't see how pspg gets any benefit --- you'll still have
to deal with the old code, for an indefinite time into the future.

Moreover, *other* programs that pay close attention to the output
format will be forced to deal with the possibility that this flag
has been turned on, which typically they wouldn't even have a way
to find out. So I think you're basically trying to export your
problems onto everyone else.

regards, tom lane


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Ahsan Hadi <ahsan(dot)hadi(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: patch: psql - enforce constant width of last column
Date: 2019-11-04 22:00:40
Message-ID: CAFj8pRCBj+ybGbOmAyHW4f-Ho4AJ2k=4Mj2ymYxCB2m7t9qyiA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

Hi

po 4. 11. 2019 v 21:55 odesílatel Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> napsal:

> Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> writes:
> > st 18. 9. 2019 v 12:52 odesílatel Ahsan Hadi <ahsan(dot)hadi(at)gmail(dot)com>
> napsal:
> >> does this patch have any value for psql without pspg?
>
> > The benefit of this patch is just for pspg users today.
>
> TBH, I think we should just reject this patch. It makes psql's
> table-printing behavior even more complicated than it was before.
> And I don't see how pspg gets any benefit --- you'll still have
> to deal with the old code, for an indefinite time into the future.
>

I don't think so it increase printing rules too much. A default value
"auto" doesn't any change against current state, "always" ensure same line
width of any row.

The problem, that this patch try to solve, is different width of rows -
although the result is aligned.

Personally I think so current behave is not correct. Correct solution
should be set "finalspaces true" every time - for aligned output. But I
don't know a motivation of authors and as solution with minimal impacts I
wrote a possibility to set (it's not default) to finalspace to "always" as
fix of some possible visual artefact (although these artefacts are almost
time invisible).

The patch maybe looks not trivial (although it is trivial), but it is due I
try to reduce possible impact on any other application to zero.

>
> Moreover, *other* programs that pay close attention to the output
> format will be forced to deal with the possibility that this flag
> has been turned on, which typically they wouldn't even have a way
> to find out. So I think you're basically trying to export your
> problems onto everyone else.
>

I try to fix this issue where this issue coming. For this patch is
important to get a agreement (or not) if this problem is a issue that
should be fixed.

I think so in aligned mode all rows should to have same width.

On second hand, really I don't know why the last space is not printed, and
if some applications had a problem with it. I have not any idea. Current
code where last spaces are not printed is little bit complex than if the
align was really complete.

Sure, "the issue of last invisible space" is not big issue (it's
triviality) - I really think so it should be fixed on psql side, but if
there will not be a agreement, I can fix it on pspg side (although it will
not be elegant - because I have to print chars that doesn't exists).

Is here any man who remember this implementation, who can say, why the code
is implemented how it is implemented?

Regards

Pavel

> regards, tom lane
>