Re: psql: add \pset true/false
Daniel Verite <daniel@manitou-mail.org>
From: "Daniel Verite" <daniel@manitou-mail.org>
To: "Jim Nasby" <Jim.Nasby@BlueTreble.com>
Cc: "Peter Eisentraut" <peter_e@gmx.net>, "Tom Lane" <tgl@sss.pgh.pa.us>,
"Marko Tiikkaja" <marko@joh.to>,
"PostgreSQL hackers" <pgsql-hackers@postgresql.org>
Date: 2015-12-03T10:48:26Z
Lists: pgsql-hackers
Jim Nasby wrote:
> I was more thinking it would be nice to be able to temporarily
> over-ride/wrap what an output function is doing. AFAIK that would allow
> this to work everywhere (row(), copy, etc). I don't know of any remotely
> practical way to do that, though.
Yes. Something like:
SET [LOCAL] OUTPUT STYLE FOR TYPE "typename" TO json_value;
where json_value would represent a set of type-dependant
parameters.
Then the type's output_function and type_modifier_output_function
refered to in CREATE TYPE could use these parameters
to customize the text representation.
For example:
SET output style FOR TYPE bool TO '{"true":"t", "false":"f"}';
or
SET output style FOR TYPE bool TO '{"true":"TRUE", "false":"FALSE"}';
This style declaration doesn't quite fit with GUCs because it should
be bound to a type, but otherwise the behavior is comparable to a
session-wide or transaction-wide SET.
Could be used for date/times too:
SET output style FOR TYPE timestamptz
TO '{"format": "DD/MM/YYYY HH24:MI TZ"}';
where applying format would essentially mean
to_char(timestamp, format), which is more flexible
than DateStyle for the output part.
Going even further, maybe some types could support:
SET output style FOR TYPE typename
TO '{"function": "funcname"}';
where the function should exist as
funcname(typename) returns text
and the type's output_function would just act as a wrapper.
or even:
SET output style FOR TYPE typename
TO '{"filter": "funcname"}';
where the function would exist as
funcname(text) returns text
and the type's output_function would call funcname
as an output filter for values already in text format.
Best regards,
--
Daniel Vérité
PostgreSQL-powered mailer: http://www.manitou-mail.org
Twitter: @DanielVerite
Commits
-
Add \pset options for boolean value display
- 645cb44c5490 19 (unreleased) landed