Skip site navigation (1) Skip section navigation (2)

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: (view raw, whole thread or download thread mbox)
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

pgsql-novice by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group