Return-Path: postman 
Delivery-Date: Mon, 20 Sep 93 06:11:36 PDT
Return-Path: postman
Received: by postgres.Berkeley.EDU (5.61/1.29)
	id AA19107; Mon, 20 Sep 93 06:08:37 -0700
Resent-From: postman (POSTGRES mailing list)
Resent-Message-Id: <9309201308.AA19107@postgres.Berkeley.EDU>
Sender: owner-postman@postgres.Berkeley.EDU
X-Return-Path: fernando@afrodita.etsimo.uniovi.es
Received: from polar.etsiig.uniovi.es by postgres.Berkeley.EDU (5.61/1.29)
	id AA19099; Mon, 20 Sep 93 06:08:15 -0700
Received: from afrodita.etsimo.uniovi.es by etsiig.uniovi.es (PMDF V4.2-10
 #4541) id <01H36C0O8M6O8WW7ZF@etsiig.uniovi.es>; Mon,
 20 Sep 1993 15:05:43 +0100 (GMT)
Received: by afrodita.etsimo.uniovi.es (5.52/890607.SGI) (for
 postgres@postgres.berkeley.edu) id AA01145; Mon, 20 Sep 93 15:08:34 MDT
Date: Mon, 20 Sep 1993 15:08:34 +0100 (MDT)
From: fernando@afrodita.etsimo.uniovi.es (Fernando Ariznavarreta)
Subject: Problems writing a function of an instance.
To: postgres@postgres.Berkeley.EDU (Postgres Lista de correo.)
Message-Id: <9309201308.AA01145@afrodita.etsimo.uniovi.es>
X-Mailer: ELM [version 2.4 PL20]
Content-Type: text
Content-Transfer-Encoding: 7BIT
Content-Length: 1888
Resent-To: postgres-dist
Resent-Date: Mon, 20 Sep 93 06:08:34 PDT

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:fernando@etsimo.uniovi.es
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

