Skip site navigation (1) Skip section navigation (2)

plperl.c patch to correctly support bytea inputs and output to functions and triggers.

From: Theo Schlossnagle <jesus(at)omniti(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Cc: Theo Schlossnagle <jesus(at)omniti(dot)com>
Subject: plperl.c patch to correctly support bytea inputs and output to functions and triggers.
Date: 2007-04-27 23:35:15
Message-ID: 7730B30B-AE7F-4431-B801-8CC5AC5ACAE3@omniti.com (view raw or flat)
Thread:
Lists: pgsql-bugs
I've found a bug with the way plperl/plperlu handles bytea types.  It  
fails to correctly handle bytea binary inputs and outputs.  Perl  
scalars are wrongly treated as C strings when a the source or  
destination tuple in postgres is of type bytea.

The attached patch alters the code path for inputs and outputs with  
the BYTEAOID type.

"Works for me"

==== begin plperl_bytea.sql ====
create or replace function pl_octet_length(bytea) returns integer as $$
return length($_[0]);
$$ language plperl;
create or replace function pl_produce_bytea() returns bytea as $$
return "\0\0\0\0\0\0see me?";
$$ language plperl;
==== end plperl_bytea.sql ===

PROBLEM:

pltest=# select pl_octet_length(E'\012\015'), octet_length(E'\012\015');
pl_octet_length | octet_length
-----------------+--------------
                8 |            2
(1 row)
pltest=# select pl_produce_bytea(), octet_length(pl_produce_bytea());
pl_produce_bytea | octet_length
------------------+--------------
                   |            0
(1 row)

AFTER PATCH:

pltest=# select pl_octet_length(E'\012\015'), octet_length(E'\012\015');
pl_octet_length | octet_length
-----------------+--------------
                2 |            2
(1 row)

pltest=# select pl_produce_bytea(), octet_length(pl_produce_bytea());
         pl_produce_bytea         | octet_length
---------------------------------+--------------
\000\000\000\000\000\000see me? |           13
(1 row)


// Theo Schlossnagle
// Principal(at)OmniTI: http://omniti.com
// Esoteric Curio: http://www.lethargy.org/~jesus/



Attachment: plperl.c.diff
Description: application/octet-stream (8.4 KB)

Responses

pgsql-bugs by date

Next:From: Tom LaneDate: 2007-04-28 17:26:41
Subject: Re: plperl.c patch to correctly support bytea inputs and output to functions and triggers.
Previous:From: Tom LaneDate: 2007-04-27 23:17:56
Subject: Re: PGSQL - WARNING: 25P01: there is no transaction in progress

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group