| From: | Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> |
|---|---|
| To: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
| Cc: | Álvaro Herrera <alvherre(at)kurilemu(dot)de>, "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
| Subject: | Fix \crosstabview to honor \pset display_true/display_false |
| Date: | 2026-06-03 07:16:13 |
| Message-ID: | B5E6F0A5-4B48-46D0-B5EB-CF8F8CC7D07D@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
While testing “[645cb44c5] Add \pset options for boolean value display”, I noticed that it seems to miss support for \crosstabview.
Here is a repro:
```
evantest=# \pset display_true YES
Boolean true display is "YES".
evantest=# \pset display_false NO
Boolean false display is "NO".
evantest=#
evantest=# select true as direct_true, false as direct_false;
direct_true | direct_false
-------------+--------------
YES | NO
(1 row)
evantest=#
evantest=# select false as row_key, true as col_key, true as val
evantest-# union all
evantest-# select true, false, false
evantest-# \crosstabview row_key col_key val
row_key | t | f
---------+---+---
f | t |
t | | f
(2 rows)
```
In normal query output, true/false are shown as YES/NO, but \crosstabview still shows them as t/f.
I noticed this problem by searching for nullPrint and finding it in crosstabview.c. Since nullPrint is already honored there, display_true/display_false should be honored as well.
While working on the fix, I further noticed that numericlocale is also not honored by \crosstabview:
```
evantest=# \pset numericlocale on
evantest=#
evantest=# SELECT 12345::numeric AS direct_value;
direct_value
--------------
12,345
(1 row)
evantest=#
evantest=# SELECT 1 AS row_key, 1 AS col_key, 12345::numeric AS val
evantest-# \crosstabview row_key col_key val
row_key | 1
---------+-------
1 | 12345
(1 row)
```
Since we are supposed to fix only v19 bugs at this stage, this patch only makes \crosstabview honor display_true/display_false, as that is a new PG19 feature. I will add the numericlocale work to my TODO and revisit it for v20.
In this patch, I add a helper function, printQueryOptDisplayValue(), to handle both nullPrint and display_true/display_false in a single place. In the future, we may also be able to handle numericlocale in this function.
See the attached patch for details. With the fix, \crosstabview displays boolean values according to the \pset settings:
```
evantest=# select false as row_key, true as col_key, true as val
evantest-# union all
evantest-# select true, false, false
evantest-# \crosstabview row_key col_key val
row_key | YES | NO
---------+-----+----
NO | YES |
YES | | NO
(2 rows)
```
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Make-crosstabview-honor-boolean-display-settings.patch | application/octet-stream | 8.5 KB |
| From | Date | Subject | |
|---|---|---|---|
| Previous Message | jian he | 2026-06-03 06:58:45 | Re: Fix bug of CHECK constraint enforceability recursion |