bool_plperl transform

Started by Ivan Panchenkoabout 6 years ago12 messageshackers
Jump to latest
#1Ivan Panchenko
wao@mail.ru

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
 
 

Attachments:

bool_plperl_transform_v1.patchapplication/octet-stream; name="=?UTF-8?B?Ym9vbF9wbHBlcmxfdHJhbnNmb3JtX3YxLnBhdGNo?="Download+41-3
#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Ivan Panchenko (#1)
Re: bool_plperl transform

=?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

#3Andrew Dunstan
andrew@dunslane.net
In reply to: Ivan Panchenko (#1)
Re: bool_plperl transform

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

#4Ivan Panchenko
wao@mail.ru
In reply to: Andrew Dunstan (#3)
Re[2]: bool_plperl transform

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
 

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

Attachments:

bool_plperl_transform_v2.patchapplication/octet-stream; name="=?UTF-8?B?Ym9vbF9wbHBlcmxfdHJhbnNmb3JtX3YyLnBhdGNo?="Download+510-0
#5Ivan Panchenko
wao@mail.ru
In reply to: Tom Lane (#2)
Re[2]: bool_plperl transform

 

Воскресенье, 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

 
 
 
 

#6Tom Lane
tgl@sss.pgh.pa.us
In reply to: Ivan Panchenko (#4)
Re: Re[2]: bool_plperl transform

=?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

In reply to: Ivan Panchenko (#4)
Re: bool_plperl transform

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

#8Ivan Panchenko
wao@mail.ru
In reply to: Dagfinn Ilmari Mannsåker (#7)
Re[2]: bool_plperl transform

 

Понедельник, 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

 

 
 
 
 

#9Ivan Panchenko
wao@mail.ru
In reply to: Tom Lane (#6)
Re[4]: bool_plperl transform

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

 
 
 
 

Attachments:

bool_plperl_transform_v3.patchapplication/octet-stream; name="=?UTF-8?B?Ym9vbF9wbHBlcmxfdHJhbnNmb3JtX3YzLnBhdGNo?="Download+547-3
#10Tom Lane
tgl@sss.pgh.pa.us
In reply to: Ivan Panchenko (#9)
Re: Re[4]: bool_plperl transform

=?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

In reply to: Tom Lane (#10)
Re[6]: bool_plperl transform

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
 
 
 

#12Tom Lane
tgl@sss.pgh.pa.us
In reply to: Ivan Panchenko (#11)
Re: Re[6]: bool_plperl transform

=?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