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

From John Gunther
Subject Re: Compiling a user C function in 7.2.1
Date
Msg-id 3D4437E8.7070403@bucksvsbytes.com
Whole thread Raw
In response to Add value in an Array  ("Jerome Chochon" <jerome.chochon@ensma.fr>)
Responses Re: Compiling a user C function in 7.2.1  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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



pgsql-novice by date:

Previous
From: Tom Lane
Date:
Subject: Re: Compiling a user C function in 7.2.1
Next
From: Tom Lane
Date:
Subject: Re: Compiling a user C function in 7.2.1