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