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

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

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



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: Binary data



Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group