Subject: C functions

From: Mike Krus <[email-masked]>
Date: Fri, 05 Feb 93 16:36:10 -0500

Ok, I'm pretty sure this is dumb question to which there is an obvious answer
but I simply can't figure it out.

I have a table PLANE of which one field named PID is of type text.
I wrote the following C function to test if the first letter is a B :

#include <tmp/libpq-fe.h>

extern char* GetAttributeByName();

bool test(plane)
TUPLE plane;
{
	char *PID;

	PID = GetAttributeByName(plane, "PID");
	return ( *PID == 'B' );
}

I define it in Postgres using the following statement :

>define function test
>	(language = "c", returntype = bool)
>	arg is (PLANE)
>	as "/home/ugrad/krus/Projects/DataBases/test.o" \g

And run the following query :

retrieve (p.PID) from p in PLANE where test(p) \g

When running monitor with the -t and -d options, I get the following output :

>The query sent to the backend: retrieve (p.all) from p in PLANE where test(p)
>The Identifier is: P
>The Transaction Id is: 0
>Portal name = blank
>Identifier is: T
>The identifier is: T

Then that last line is repeated (apparently) endlessly.
What is wrong with what I'm doing (or with postgres for that matter :-)?
And what is the meaning of the various values that identifier that comes back
all the time?

Note : I know I could rewrite the function to take the field directly as a
parameter, but I'll need to perform more complicated tests.

Related question : can a C function like the one above call functions from the
standard C library, i.e. is the library linked in some way to the back end?

Thanks for your help,

--------
Michael Krus.					 Email : [email-masked]
Concordia University				Universite d'Orsay - Paris XI
Montreal, Canada					        Paris, France
"Western civilisation? It would be a good idea!" -- Gandhi