Обсуждение: bool_plperl transform

Поиск
Список
Период
Сортировка

bool_plperl transform

От
Ivan Panchenko
Дата:
Hi,
While using PL/Perl I have found that it obtains boolean arguments from Postgres as ‘t’ and ‘f’, which is extremely inconvenient because ‘f’ is not false from the perl viewpoint.
So the problem is how to convert the SQL booleans into Perl style.
 
There are 3 ways to do this:
  1. make plperl automatically convert bools into something acceptable for perl. This looks simple, but probably is not acceptable as it breaks compatibility.
  2. try to make some trick like it is done with arrays, i.e. convert bools into special Perl objects which look like ‘t’ and ‘f’ when treated as text, but are true and false for boolean operations. I am not sure that it is possible and reliable.
  3. make a transform which transforms bool, like it is done with jsonb. This does not break compatibility and is rather straightforward.
So I propose to take the third way and make such transform. This is very simple, a patch is attached.
Also this patch improves the plperl documentation page, which now has nothing said about the transforms.
 
Regards,
Ivan Panchenko
 
 
Вложения

Re: bool_plperl transform

От
Tom Lane
Дата:
=?UTF-8?B?SXZhbiBQYW5jaGVua28=?= <wao@mail.ru> writes:
> While using PL/Perl I have found that it obtains boolean arguments from Postgres as ‘t’ and ‘f’, which is extremely
inconvenientbecause ‘f’ is not false from the perl viewpoint. 
> ...
> *  make a transform which transforms bool, like it is done with jsonb. This does not break compatibility and is
ratherstraightforward. 

Please register this patch in the commitfest app, so we don't lose track
of it.

https://commitfest.postgresql.org/27/

            regards, tom lane



Re: bool_plperl transform

От
Andrew Dunstan
Дата:
On 2/29/20 4:55 PM, Ivan Panchenko wrote:
> Hi,
> While using PL/Perl I have found that it obtains boolean arguments
> from Postgres as ‘t’ and ‘f’, which is extremely inconvenient because
> ‘f’ is not false from the perl viewpoint.
> So the problem is how to convert the SQL booleans into Perl style.
>  
> There are 3 ways to do this:
>
>  1. make plperl automatically convert bools into something acceptable
>     for perl. This looks simple, but probably is not acceptable as it
>     breaks compatibility.
>  2. try to make some trick like it is done with arrays, i.e. convert
>     bools into special Perl objects which look like ‘t’ and ‘f’ when
>     treated as text, but are true and false for boolean operations. I
>     am not sure that it is possible and reliable.
>  3. make a transform which transforms bool, like it is done with
>     jsonb. This does not break compatibility and is rather
>     straightforward.
>
> So I propose to take the third way and make such transform. This is
> very simple, a patch is attached.
> Also this patch improves the plperl documentation page, which now has
> nothing said about the transforms.
>  
>


Patch appears to be missing all the new files.


cheers


andrew



-- 
Andrew Dunstan                https://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services




Re[2]: bool_plperl transform

От
Wao
Дата:
Sorry,
 
Please find the full patch attached.
 
Ivan
 
Воскресенье, 1 марта 2020, 7:57 +03:00 от Andrew Dunstan <andrew.dunstan@2ndquadrant.com>:
 

On 2/29/20 4:55 PM, Ivan Panchenko wrote:
> Hi,
> While using PL/Perl I have found that it obtains boolean arguments
> from Postgres as ‘t’ and ‘f’, which is extremely inconvenient because
> ‘f’ is not false from the perl viewpoint.
> So the problem is how to convert the SQL booleans into Perl style.
>  
> There are 3 ways to do this:
>
> 1. make plperl automatically convert bools into something acceptable
> for perl. This looks simple, but probably is not acceptable as it
> breaks compatibility.
> 2. try to make some trick like it is done with arrays, i.e. convert
> bools into special Perl objects which look like ‘t’ and ‘f’ when
> treated as text, but are true and false for boolean operations. I
> am not sure that it is possible and reliable.
> 3. make a transform which transforms bool, like it is done with
> jsonb. This does not break compatibility and is rather
> straightforward.
>
> So I propose to take the third way and make such transform. This is
> very simple, a patch is attached.
> Also this patch improves the plperl documentation page, which now has
> nothing said about the transforms.
>  
>


Patch appears to be missing all the new files.


cheers


andrew



--
Andrew Dunstan https://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
 
 
 
--
Иван Панченко
 
Вложения

Re[2]: bool_plperl transform

От
Ivan Panchenko
Дата:


 
Воскресенье, 1 февраля 2020, 1:15 +03:00 от Tom Lane <tgl@sss.pgh.pa.us>:
 
Ivan Panchenko <wao@mail.ru> writes:
> While using PL/Perl I have found that it obtains boolean arguments from Postgres as ‘t’ and ‘f’, which is extremely inconvenient because ‘f’ is not false from the perl viewpoint.
> ...
> * make a transform which transforms bool, like it is done with jsonb. This does not break compatibility and is rather straightforward.

Please register this patch in the commitfest app, so we don't lose track
of it.

https://commitfest.postgresql.org/27/
Done:
 
Regards,
Ivan
 

regards, tom lane
 
 
 
 

Re: Re[2]: bool_plperl transform

От
Tom Lane
Дата:
=?UTF-8?B?V2Fv?= <wao@mail.ru> writes:
> Please find the full patch attached.

The cfbot shows this failing to build on Windows:

https://ci.appveyor.com/project/postgresql-cfbot/postgresql/build/1.0.81889

I believe that's a build without plperl, so what it's probably telling
you is that Mkvcbuild.pm needs to be taught to build this module
conditionally, as it already does for hstore_plperl and jsonb_plperl.

Also, while the Linux build is passing, I can't find that it is actually
compiling or testing bool_plperl anywhere:

https://travis-ci.org/postgresql-cfbot/postgresql/builds/656909114

This is likely because you didn't add it to contrib/Makefile.

In general, I'd suggest grepping for references to hstore_plperl
or jsonb_plperl, and making sure that bool_plperl gets added where
appropriate.

I rather imagine you need a .gitignore file, as well.

You're also going to have to provide some documentation, because
I don't see any in the patch.

            regards, tom lane



Re: bool_plperl transform

От
ilmari@ilmari.org (Dagfinn Ilmari Mannsåker)
Дата:
Wao <wao@mail.ru> writes:

> +Datum
> +bool_to_plperl(PG_FUNCTION_ARGS)
> +{
> +    dTHX;
> +    bool in = PG_GETARG_BOOL(0);
> +    SV    *sv = newSVnv(SvNV(in ? &PL_sv_yes : &PL_sv_no));
> +    return PointerGetDatum(sv);
> +}

Why is this only copying the floating point part of the built-in
booleans before returning them?  I think this should just return
&PL_sv_yes or &PL_sv_no directly, like boolean expressions in Perl do,
and like what happens for NULL (&PL_sv_undef).

- ilmari
-- 
"A disappointingly low fraction of the human race is,
 at any given time, on fire." - Stig Sandbeck Mathisen



Re[2]: bool_plperl transform

От
Ivan Panchenko
Дата:


 
Понедельник, 2 марта 2020, 1:09 +03:00 от ilmari@ilmari.org:
 
Wao <wao@mail.ru> writes:
 
> +Datum
> +bool_to_plperl(PG_FUNCTION_ARGS)
> +{
> + dTHX;
> + bool in = PG_GETARG_BOOL(0);
> + SV *sv = newSVnv(SvNV(in ? &PL_sv_yes : &PL_sv_no));
> + return PointerGetDatum(sv);
> +}

Why is this only copying the floating point part of the built-in
booleans before returning them? I think this should just return
&PL_sv_yes or &PL_sv_no directly, like boolean expressions in Perl do,
and like what happens for NULL (&PL_sv_undef).
Thanks, I will fix this in the next version of the patch.
 
Regards,
Ivan

- ilmari
--
"A disappointingly low fraction of the human race is,
 at any given time, on fire." - Stig Sandbeck Mathisen

 
 
 
 
 

Re[4]: bool_plperl transform

От
Ivan Panchenko
Дата:
Thanks, Tom.
 
I think now it should build, please find the fixed patch attached.
I had no possibility to check it on Windows now, but the relevant changes in Mkvcbuild.pm are done, so I hope it should work.
The documentation changes are also included in the same patch.
 
Regards,
Ivan
 
Понедельник, 2 марта 2020, 0:14 +03:00 от Tom Lane <tgl@sss.pgh.pa.us>:
 
Wao <wao@mail.ru> writes:
> Please find the full patch attached.

The cfbot shows this failing to build on Windows:

https://ci.appveyor.com/project/postgresql-cfbot/postgresql/build/1.0.81889

I believe that's a build without plperl, so what it's probably telling
you is that Mkvcbuild.pm needs to be taught to build this module
conditionally, as it already does for hstore_plperl and jsonb_plperl.

Also, while the Linux build is passing, I can't find that it is actually
compiling or testing bool_plperl anywhere:

https://travis-ci.org/postgresql-cfbot/postgresql/builds/656909114

This is likely because you didn't add it to contrib/Makefile.

In general, I'd suggest grepping for references to hstore_plperl
or jsonb_plperl, and making sure that bool_plperl gets added where
appropriate.

I rather imagine you need a .gitignore file, as well.

You're also going to have to provide some documentation, because
I don't see any in the patch.

regards, tom lane
 
 
 
 
Вложения

Re: Re[4]: bool_plperl transform

От
Tom Lane
Дата:
=?UTF-8?B?SXZhbiBQYW5jaGVua28=?= <wao@mail.ru> writes:
> [ bool_plperl_transform_v3.patch ]

I reviewed this, fixed some minor problems (mostly cosmetic, but not
entirely), and pushed it.

Thanks for the contribution!

            regards, tom lane



Re[6]: bool_plperl transform

От
Ivan Panchenko
Дата:
Tom,
 
Суббота, 7 марта 2020, 1:15 +03:00 от Tom Lane <tgl@sss.pgh.pa.us>:
 
Ivan Panchenko <wao@mail.ru> writes:
> [ bool_plperl_transform_v3.patch ]

I reviewed this, fixed some minor problems (mostly cosmetic, but not
entirely), and pushed it.

Thanks for the commit and for your work improving the patch.
 
Do you think the jsonb transform is worth explicit mentioning at the PL/Perl documentation page, or not?
 

Thanks for the contribution!

regards, tom lane
 

Regards,
Ivan
 
 
 

Re: Re[6]: bool_plperl transform

От
Tom Lane
Дата:
=?UTF-8?B?SXZhbiBQYW5jaGVua28=?= <wao@mail.ru> writes:
> Do you think the jsonb transform is worth explicit mentioning at the PL/Perl documentation page, or not?

Right now it's documented under the json data types, which seems
sufficient to me.

            regards, tom lane