Subject: Problems writing a function of an instance.

From: [email-masked] (Fernando Ariznavarreta)
Date: Mon, 20 Sep 1993 15:08:34 +0100 (MDT)

I've tried to write a C function which receives a tuple and returns a value
as indicated in the users manual. But I couldn't do it.
Which header files should I use in my source code? 
I tried to use "tmp/libpq-be.h" but the code fails to compile as in this files
there is no TUPLE definition nor GetAttributebyName() function declaration.
Then I used "tmp/libpq-fe.h" and the code compiles but it doesn't work.

Here is my implementation:

create SAMPLES(burden= float4) /* this is a simplified class */
\g
define function neural_net (language= "C",returntype= int2)
arg is (SAMPLES)
as "/usr/ropes/initdb/neuralnet.o"
\g

Here is the code for the C function (a simplified version):
#include "tmp/libpq-fe.h"
#include "tmp/postgres.h"

int2 neural_net(tp)
TUPLE tp;
{
   float4 burden;
   burden = (float4) GetAttributebyName(tp,"burden");
   return (int2) burden;
}

Now let's append some data...

append SAMPLES(burden= 2.6)\g

... and try the new function:

retrieve (SAMPLES.burden,t= SAMPLES.neural_net)\g

The answer is:
Query sent to backend is "retrieve (SAMPLES.burden,t= SAMPLES.neural_net)"
WARN:Sep 20 15:04:18:Load of file /usr/ropes/initdb/neuralnet.o failed: link fai
led
led

if you make: load "/usr/ropes/initdb/neuralnet.o"
you get the same answer.

The file neuralnet.o is in the directory /usr/ropes/initdb/neuralnet.o
and has appropiate permisions (666).

I've tried this using a test function wich gets an int2 and returns
an int2 and everything worked OK.

Where is the problem with my code?

Any idea will be welcome.

-- 
Fernando Ariznavarreta Fernandez       E-Mail:[email-masked]
Dpto. Explotacion y Prospeccion de Minas     Phone: +34 8 510 4267
School of Mines. University of Oviedo               +34 8 510 4336
Independencia, 13                            Fax:   +34 8 510 4242
Oviedo 33004, SPAIN                                 +34 8 510 4340