Re: Fix \crosstabview to honor \pset display_true/display_false - Mailing list pgsql-hackers

From David G. Johnston
Subject Re: Fix \crosstabview to honor \pset display_true/display_false
Date
Msg-id CAKFQuwb-MdD3gjpJ5hMDSMgNJDykOArrA2_orA29VzLTy9=ELw@mail.gmail.com
Whole thread
In response to Fix \crosstabview to honor \pset display_true/display_false  (Chao Li <li.evan.chao@gmail.com>)
List pgsql-hackers
On Wed, Jun 3, 2026 at 12:16 AM Chao Li <li.evan.chao@gmail.com> wrote:
While testing “[645cb44c5] Add \pset options for boolean value display”, I noticed that it seems to miss support for \crosstabview.

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.


Thanks Chao!

Adding a function indeed seems like the best choice - the only question is whether expanding print.h at this point is acceptable.  If not, making it private to crosstab.c will accomplish the same immediate need.

The name is a bit odd to me but I'm also not that familiar with naming conventions in the C code.  But this is another reason to make it private in v19 and figure out the public interface in v20.

> cont.cells[idx] =
> printQueryOptDisplayValue(!PQgetisnull(result, rn, field_for_data) ?
> PQgetvalue(result, rn, field_for_data) :
> NULL,
> data_ftype, &popt, "");

I'd either remove the not operator and flip the order of the output ternary positions, or move the entire "compute the unadjusted value" to a local variable (assignment from ternary or just an if block) and then pass it to printQueryOptDisplayValue directly.  Having a ternary expression as the first argument is what the other changes got rid of and makes this much easier to read (hence the need for the function).

David J.

pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: PG20 Minimum Dependency Thread
Next
From: "Tristan Partin"
Date:
Subject: Re: Fix publisher-side sequence permission reporting