Re: Compiling a user C function in 7.2.1

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: John Gunther <inbox(at)bucksvsbytes(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Compiling a user C function in 7.2.1
Date: 2002-07-29 07:04:26
Message-ID: 14941.1027926266@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

John Gunther <inbox(at)bucksvsbytes(dot)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

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Wim 2002-07-29 12:58:35 Still problems with pg_dump ad \dt...
Previous Message John Gunther 2002-07-28 18:28:56 Re: Compiling a user C function in 7.2.1