Re: Compiling a user C function in 7.2.1

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Compiling a user C function in 7.2.1
Дата
Msg-id 14941.1027926266@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Compiling a user C function in 7.2.1  (John Gunther <inbox@bucksvsbytes.com>)
Список pgsql-novice
John Gunther <inbox@bucksvsbytes.com> writes:
> Datum bvbpgsortword(PG_FUNCTION_ARGS){
> //declarations
>     text                    *instr = PG_GETARG_TEXT_P(0);
>     text                    *outstr;
> //code
>     memcpy(outstr,"abcdef",6);//needed to move data from char constant
> to pg's text type?
>     VARATT_SIZEP(outstr) = 6 + VARHDRSZ;//set length for text value?
>     PG_RETURN_TEXT_P(outstr);//return text value, i.e. 'abcdef', to
> PostgreSQL?
> }

You're missing a palloc() (didn't your compiler warn about use of an
uninitialized variable here?).  And the memcpy needs to point at
VARDATA(outstr) not just outstr.

            regards, tom lane

В списке pgsql-novice по дате отправления:

Предыдущее
От: John Gunther
Дата:
Сообщение: Re: Compiling a user C function in 7.2.1
Следующее
От: "Jim Steil"
Дата:
Сообщение: Auto-incrementing field