Re: psql: add \pset true/false

Поиск
Список
Период
Сортировка
От Kyotaro HORIGUCHI
Тема Re: psql: add \pset true/false
Дата
Msg-id 20151203.100923.43833412.horiguchi.kyotaro@lab.ntt.co.jp
обсуждение исходный текст
Ответ на Re: psql: add \pset true/false  (Michael Paquier <michael.paquier@gmail.com>)
Ответы Re: psql: add \pset true/false  (Michael Paquier <michael.paquier@gmail.com>)
Список pgsql-hackers
Hello,

At Thu, 3 Dec 2015 09:24:35 +0900, Michael Paquier <michael.paquier@gmail.com> wrote in
<CAB7nPqTTZXaiVj0_FWvp8hPLLD_yDa8cnS4iuy_HgSOgFz09HA@mail.gmail.com>
> On Thu, Dec 3, 2015 at 3:10 AM, Jim Nasby <Jim.Nasby@bluetreble.com> wrote:
> > On 11/15/15 7:37 PM, Peter Eisentraut 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.
> 
> You can basically do that with a custom data type and at worse a
> custom GUC, no? It does not seem worth bothering the backend with an
> extra layer to manage the output of a data type.

How about plugins on psql side? Calling hooked function in
printQuery could do that on psql. Impact on psql itself is
minimized. (Of course code for loading is omitted in the below
but it would also small...)

> --- a/src/bin/psql/print.c
> @@ -3210,6 +3210,10 @@ printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, FILE *f
>        else
>        {
>          cell = PQgetvalue(result, r, c);
> +        if (outputplugin)
> +          char *cell = outputplugin(cell, PQftype(result, c),
> +                                    &mustfree);
>          if (cont.aligns[c] == 'r' && opt->topt.numericLocale)
>          {
>            cell = format_numeric_locale(cell);



One problem of this is who wants to do this must write a
program. But someone might write general purpose plugin.


=$ loadlib 'outputhook.so';
=$ select 't'::bool;bool 
------X
(1 row)

=== outputhook.so
char *
outputhook(char *origcell, type, bool *mustfree)
{  char *retcell;
  switch (type)  {  case BOOLOID:    retcell = (*origcell == 't' ? 'TRRRRUEEE' : "FAAALSE");    if (*mustfree)
free(origcell);   *mustfree = false;    break;  default:    retcell = origcell;    break;  }  return retcell;
 
}
=====

regards,

-- 
Kyotaro Horiguchi
NTT Open Source Software Center





В списке pgsql-hackers по дате отправления:

Предыдущее
От: Craig Ringer
Дата:
Сообщение: Re: Logical replication and multimaster
Следующее
От: Craig Ringer
Дата:
Сообщение: Re: Logical replication and multimaster