bool_plperl transform

Lists: pgsql-hackers
From: Ivan Panchenko <wao(at)mail(dot)ru>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: bool_plperl transform
Date: 2020-02-29 21:55:17
Message-ID: 1583013317.881182688@f390.i.mail.ru
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers


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
 
 

Attachment Content-Type Size
bool_plperl_transform_v1.patch application/octet-stream 3.6 KB

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Ivan Panchenko <wao(at)mail(dot)ru>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: bool_plperl transform
Date: 2020-02-29 22:15:48
Message-ID: 6153.1583014548@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

=?UTF-8?B?SXZhbiBQYW5jaGVua28=?= <wao(at)mail(dot)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


From: Andrew Dunstan <andrew(dot)dunstan(at)2ndquadrant(dot)com>
To: Ivan Panchenko <wao(at)mail(dot)ru>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: bool_plperl transform
Date: 2020-03-01 04:57:47
Message-ID: 16cbcd48-d5cb-72a5-5447-7714caff238e@2ndQuadrant.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers


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


From: Wao <wao(at)mail(dot)ru>
To: Andrew Dunstan <andrew(dot)dunstan(at)2ndquadrant(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re[2]: bool_plperl transform
Date: 2020-03-01 08:02:10
Message-ID: 1583049730.278871202@f150.i.mail.ru
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers


Sorry,
 
Please find the full patch attached.
 
Ivan
 
>Воскресенье, 1 марта 2020, 7:57 +03:00 от Andrew Dunstan <andrew(dot)dunstan(at)2ndquadrant(dot)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

 
 
--
Иван Панченко
 

Attachment Content-Type Size
bool_plperl_transform_v2.patch application/octet-stream 12.8 KB

From: Ivan Panchenko <wao(at)mail(dot)ru>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re[2]: bool_plperl transform
Date: 2020-03-01 11:14:41
Message-ID: 1583061281.258805870@f317.i.mail.ru
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

 
>Воскресенье, 1 февраля 2020, 1:15 +03:00 от Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:

>=?UTF-8?B?SXZhbiBQYW5jaGVua28=?= < wao(at)mail(dot)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
 
 
 
 


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Wao <wao(at)mail(dot)ru>
Cc: Andrew Dunstan <andrew(at)dunslane(dot)net>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Re[2]: bool_plperl transform
Date: 2020-03-01 21:13:57
Message-ID: 5578.1583097237@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

=?UTF-8?B?V2Fv?= <wao(at)mail(dot)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


From: ilmari(at)ilmari(dot)org (Dagfinn Ilmari Mannsåker )
To: Wao <wao(at)mail(dot)ru>
Cc: Andrew Dunstan <andrew(dot)dunstan(at)2ndquadrant(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: bool_plperl transform
Date: 2020-03-01 22:09:37
Message-ID: 87h7z7wwv2.fsf@wibble.ilmari.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

Wao <wao(at)mail(dot)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


From: Ivan Panchenko <wao(at)mail(dot)ru>
To: ilmari(at)ilmari(dot)org
Cc: Andrew Dunstan <andrew(dot)dunstan(at)2ndquadrant(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re[2]: bool_plperl transform
Date: 2020-03-01 23:30:46
Message-ID: 1583105446.157155716@f330.i.mail.ru
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

 
>Понедельник, 2 марта 2020, 1:09 +03:00 от ilmari(at)ilmari(dot)org:

>Wao < wao(at)mail(dot)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
>

 
 
 
 


From: Ivan Panchenko <wao(at)mail(dot)ru>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Andrew Dunstan <andrew(at)dunslane(dot)net>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re[4]: bool_plperl transform
Date: 2020-03-02 00:01:40
Message-ID: 1583107300.299213059@f529.i.mail.ru
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers


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(at)sss(dot)pgh(dot)pa(dot)us>:

>=?UTF-8?B?V2Fv?= < wao(at)mail(dot)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
 
 
 
 

Attachment Content-Type Size
bool_plperl_transform_v3.patch application/octet-stream 16.5 KB

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Ivan Panchenko <wao(at)mail(dot)ru>
Cc: Andrew Dunstan <andrew(at)dunslane(dot)net>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Re[4]: bool_plperl transform
Date: 2020-03-06 22:15:09
Message-ID: 26335.1583532909@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

=?UTF-8?B?SXZhbiBQYW5jaGVua28=?= <wao(at)mail(dot)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


From: Ivan Panchenko <wao(at)mail(dot)ru>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Andrew Dunstan <andrew(at)dunslane(dot)net>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re[6]: bool_plperl transform
Date: 2020-03-07 15:07:24
Message-ID: 1583593644.665049086@f173.i.mail.ru
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers


Tom,
 
>Суббота, 7 марта 2020, 1:15 +03:00 от Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:

>=?UTF-8?B?SXZhbiBQYW5jaGVua28=?= < wao(at)mail(dot)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
 
 
 


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Ivan Panchenko <wao(at)mail(dot)ru>
Cc: Andrew Dunstan <andrew(at)dunslane(dot)net>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Re[6]: bool_plperl transform
Date: 2020-03-07 15:34:39
Message-ID: 7949.1583595279@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

=?UTF-8?B?SXZhbiBQYW5jaGVua28=?= <wao(at)mail(dot)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