User built functions?

Started by Rick Dearmanabout 27 years ago1 messagesgeneral
Jump to latest
#1Rick Dearman
rdear@gameszone.net

I want to create a C funtion for my postgresql database which is passed
an int4 type and returns a string?

I attempted to do:

create function to_string(int4) returns varchar as 'to_stardate($1)'
language 'C';

and a function like this:

#include "executor/executor.h" /* for GetAttributeByName() */
#include <string.h>
#include <stdio.h>
#include "postgres.h" /* for char16, etc. */
#include "utils/palloc.h" /* for palloc */
#include "libpq-fe.h"

char *
#ifdef __STDC__
to_string (int integer_type, char *string)
#else /* __STDC__ */
to_string (interger_type)
int integer_type;
char *stardate;
#endif /* __STDC__ */
{

string = palloc(255);
sprintf( string, "[%d]", integer_type);
return string;

}

However this gives me an error like this:
ERROR: stat failed on file to_string($1)

I looked in my pg_language table and have

C listed under /bin/cc however the only compiler on my machine is in
/usr/local/bin/gcc could this be the problem?