bool_plperl

A contrib module providing a boolean transform for PL/Perl

bool_plperl is a contrib module providing a boolean transform for PL/Perl.

bool_plperl was introduced in PostgreSQL 14.

Schema

bool_plperl will be installed into the current schema, or the schema specified with CREATE EXTENSION ... SCHEMA ... .

Change history

Examples

Usage example:

postgres=# CREATE EXTENSION bool_plperl CASCADE;
NOTICE:  installing required extension "plperl"
CREATE EXTENSION

postgres=# CREATE FUNCTION hello_bool(bool)
             RETURNS TEXT
             TRANSFORM FOR TYPE bool
             LANGUAGE plperl
           AS $$
             my $with_world = shift;

             elog(INFO, "with_world: '$with_world'");
return sprintf('hello%s', $with_world ? ' world' : ''); $$; CREATE FUNCTION postgres=# SELECT hello_bool(true), hello_bool(false);
INFO: with_world: '1'
INFO: with_world: '' hello_bool | hello_bool -------------+------------ hello world | hello (1 row)

The equivalent function without using a transform results in the FALSE value being passed as literal 'f', which (unless explicitly converted by the function) will not be interpreted as a boolean value in the normal way:

postgres=# CREATE OR REPLACE FUNCTION hello_nobool(bool)
             RETURNS TEXT
             LANGUAGE plperl
           AS $$
             my $with_world = shift;

             elog(INFO, "with_world: '$with_world'");
           
             return sprintf('hello%s', $with_world ? ' world' : '');
           $$;
CREATE FUNCTION

postgres=# SELECT hello_nobool(true), hello_nobool(false);
INFO:  with_world: 't'
INFO:  with_world: 'f'
 hello_nobool | hello_nobool 
--------------+--------------
 hello world  | hello world
(1 row)

Categories

Contrib module, Extension, Procedural language

See also

bool_plperlu