Re: [GENERAL] c function return not recognized? - Mailing list pgsql-general

From Gene Selkov Jr.
Subject Re: [GENERAL] c function return not recognized?
Date
Msg-id 199912120635.AAA29334@mail.xnet.com
Whole thread Raw
In response to c function return not recognized?  (Frank Miles <fpm@u.washington.edu>)
List pgsql-general
Frank Miles wrote:

> I've got an external  C function that I call from a SELECT, for example:
>
> select * from <table> where <cond1> and CFunction(columnName) > 1.0;
>
> The 'CFunction' has been installed into Postgreql using CREATE FUNCTION,
> with a single 'text' argument, and returning a float8 (i.e. double).

This is becoming a VFAQ, which is nice because it means that the
extensibility features gain popularity (which IMO make postgres stand
out very impressively), but it is disturbing that the message in the
docs and in examples is not getting through.

One can't get anything back from a C function by other means than
reference. One needs to first palloc() the space for the value and
then return the pointer to it. The reason Frank's function behaved as
he describes is likely because the caller treats the return values as
pointers which indeed points to random locations depending on the
input.

There could be other reasons, too, but then again, it is always helpful
to paste a bit of your code so we don't have to speculate about the
exact nature of your problem.

--Gene


pgsql-general by date:

Previous
From: Frank Miles
Date:
Subject: c function return not recognized?
Next
From: Robert
Date:
Subject: Re: [GENERAL] Czech Win1250 sorting q