Thread
Commits
-
Create contrib/bool_plperl to provide a bool transform for PL/Perl[U].
- 36058a3c55d2 13.0 landed
-
bool_plperl transform
Ivan Panchenko <wao@mail.ru> — 2020-02-29T21:55:17Z
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: * make plperl automatically convert bools into something acceptable for perl. This looks simple, but probably is not acceptable as it breaks compatibility. * 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. * 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 <tgl@sss.pgh.pa.us> — 2020-02-29T22:15:48Z
=?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 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/ regards, tom lane
-
Re: bool_plperl transform
Andrew Dunstan <andrew.dunstan@2ndquadrant.com> — 2020-03-01T04:57:47Z
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 <wao@mail.ru> — 2020-03-01T08:02:10Z
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 <wao@mail.ru> — 2020-03-01T11:14:41Z
>Воскресенье, 1 февраля 2020, 1:15 +03:00 от Tom Lane <tgl@sss.pgh.pa.us>: > >=?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 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: https://commitfest.postgresql.org/27/2502/ Regards, Ivan > >regards, tom lane
-
Re: Re[2]: bool_plperl transform
Tom Lane <tgl@sss.pgh.pa.us> — 2020-03-01T21:13:57Z
=?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
Dagfinn Ilmari Mannsåker <ilmari@ilmari.org> — 2020-03-01T22:09:37Z
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 <wao@mail.ru> — 2020-03-01T23:30:46Z
>Понедельник, 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 <wao@mail.ru> — 2020-03-02T00:01:40Z
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>: > >=?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: Re[4]: bool_plperl transform
Tom Lane <tgl@sss.pgh.pa.us> — 2020-03-06T22:15:09Z
=?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 <wao@mail.ru> — 2020-03-07T15:07:24Z
Tom, >Суббота, 7 марта 2020, 1:15 +03:00 от Tom Lane <tgl@sss.pgh.pa.us>: > >=?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 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 <tgl@sss.pgh.pa.us> — 2020-03-07T15:34:39Z
=?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