Обсуждение: Creating a Function with C that returns bytea

Поиск
Список
Период
Сортировка

Creating a Function with C that returns bytea

От
David Busby
Дата:
List,
    I'm building this function in C that will return a bytea (hopefully) and
cannot get it to return the bytea value.  Am I missing something really
simple


My code is similar to this:

#include <necessary files>
bytea *func() {
    bytea *x = palloc(36);
    // code to load the 36 bytes here
    return x;
}




Re: Creating a Function with C that returns bytea

От
Tom Lane
Дата:
David Busby <busby@pnts.com> writes:
> My code is similar to this:

> #include <necessary files>
> bytea *func() {
>     bytea *x = palloc(36);
>     // code to load the 36 bytes here
>     return x;
> }

Are you setting the bytea's length word correctly?

            regards, tom lane

Re: Creating a Function with C that returns bytea

От
Joe Conway
Дата:
David Busby wrote:
> List,
>     I'm building this function in C that will return a bytea (hopefully)
> and
> cannot get it to return the bytea value.  Am I missing something really
> simple
>
>
> My code is similar to this:
>
> #include <necessary files>
> bytea *func() {
>     bytea *x = palloc(36);
>     // code to load the 36 bytes here
>     return x;
> }
>

To be helpful, we probably need more detail, but you should start with
section "12.5.4. Version-1 Calling Conventions for C-Language Functions" at:
http://www.postgresql.org/idocs/index.php?xfunc-c.html

You want to use "PG_RETURN_BYTEA_P(x)" to return bytea data from a user
function. Look at the "copytext(PG_FUNCTION_ARGS)" for an example of how
to deal with the size header.

HTH,

Joe