From: | Dawid Kuroczko <qnex42(at)gmail(dot)com> |
---|---|
To: | pgsql-hackers(at)postgresql(dot)org |
Subject: | '\0' characters in procedural languages. |
Date: | 2004-11-01 18:01:43 |
Message-ID: | 758d5e7f041101100127b05730@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hello, recently I've been trying to write a plperlu function like this:
CREATE FUNCTION foo RETURNS bytea AS '
use Storable qw(freeze thaw);
my @a = (1,2,3,4,5);
return freeze (\(at)a);
' LANGUAGE plperlu;
In other words, serialize some data (maybe some rows, would be a great
aggregate function :)) and store it in some table.
And I also wrote similar function which thaws the data from bytea argument.
PostgreSQL however seems to be doing two things:
1) when returning any data from function (including bytea return
type), it copies it up to first '\0' character. Looking at the
plperl.c sources, solution would be changing lines like this:
result = FunctionCall3(&prodesc->result_in_func,
PointerGetDatum(SvPV(*svp, PL_na)),
ObjectIdGetDatum(prodesc->result_typioparam),
Int32GetDatum(-1));
into something like this:
size_t ret_length; /* size_t? */
(...)
result = FunctionCall3(&prodesc->result_in_func,
PointerGetDatum(SvPV(*svp, ret_length)),
ObjectIdGetDatum(prodesc->result_typioparam),
Int32GetDatum(-1));
In other words, use the fact that SvPV's second argument is used to
pass string length ... but I don't know where to pass the returned
length. I don't suppose (-1) is the right place...
2) When function receives bytea as an argument it converts it into
\NNN-escaped string. I think it would be more natural to pass
unescaped string to a perl function.
Ah, and while we are at it -- I think it could be nice to embed
Storable module (functions freeze, nfreeze and thaw) into plperl --
ability to pass "raw serialized" perl data between functions, and
store it in tables could be quite useful.
Regards,
Dawid
From | Date | Subject | |
---|---|---|---|
Next Message | Gaetano Mendola | 2004-11-01 19:26:32 | UPDATE is not allowed in a non-volatile function |
Previous Message | Andrew Dunstan | 2004-11-01 17:19:40 | Re: make check error on -HEAD |