Re: Compiling a user C function in 7.2.1

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

Tom Lane wrote:

>I think it would work to mention the other .so file as a library in
>the link command for bvbpglib.so.
>
>
Thanks again Tom. That did the trick for getting CREATE FUNCTION to
complete.

Sorry to be such a pain folks, but please be patient or just ignore me.
I now have what appears to be a C function extension to PostgreSQL, but
it's not returning any visible value, most likely because my C code
isn't doing what I want it to. Here's a trivial version of the function
-- all I want it to do is return "abcdef", regardless of the input received.

#include "postgres.h"
#include "fmgr.h"
#include <string.h>
Datum bvbpgsortword(PG_FUNCTION_ARGS);
PG_FUNCTION_INFO_V1(bvbpgsortword);
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?
}

Here's my SQL statement:
SELECT proname, bvbpgsortword("proname") FROM pg_proc;

The query result has procedure names in column1 and nothing in column 2.

I'm doubtless making some fundamental mistake here.

John Gunther

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2002-07-29 07:04:26 Re: Compiling a user C function in 7.2.1
Previous Message Tom Lane 2002-07-28 17:12:45 Re: Compiling a user C function in 7.2.1