Re: Compiling a user C function in 7.2.1 - Mailing list pgsql-novice

From Tom Lane
Subject Re: Compiling a user C function in 7.2.1
Date
Msg-id 14941.1027926266@sss.pgh.pa.us
Whole thread Raw
In response to Re: Compiling a user C function in 7.2.1  (John Gunther <inbox@bucksvsbytes.com>)
List 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 by date:

Previous
From: John Gunther
Date:
Subject: Re: Compiling a user C function in 7.2.1
Next
From: "Jim Steil"
Date:
Subject: Auto-incrementing field