Creating server-side functions: one simple error

From: Ruslan A Dautkhanov <rusland(at)scn(dot)ru>
To: pgsql-bugs(at)postgresql(dot)org
Subject: Creating server-side functions: one simple error
Date: 2002-10-09 11:39:38
Message-ID: 3DA4157A.1DA9078C@scn.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hi,

I have to create my own function in C lanuage, which
will use SPI. The problem that when I had done all things,
PostgreSQL says:
isbs=# select pgf1test('123');
ERROR: Can't find function pgf1test in file /usr/local/pgsql/lib/pgf1test.so

I don't know where problems is. The program is very short, please
point me where my mistake?

pgf1test.c
----------
#include "executor/spi.h"
#include <ctype.h>

Datum pgf1test(PG_FUNCTION_ARGS);
PG_FUNCTION_INFO_V1(pgf1test);

Datum
pgf1test(PG_FUNCTION_ARGS)
{
// text tnum = PG_GETARG_NAME(0);
char *cnum = PG_GETARG_CSTRING(0);
PG_RETURN_INT32( atoi(cnum) );
}

compile.sh
----------
#!/bin/sh

NAME=pgf1test

gcc -pipe -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -fpic -DPIC \
-I. -I/usr/home/rd/postgresql/src/include -c -o ${NAME}.o ${NAME}.c

/usr/libexec/elf/ld -x -shared -o ${NAME}.so ${NAME}.o
rm ${NAME}.o

pgf1test-createfunc.sql
-----------------------
CREATE OR REPLACE FUNCTION pgf1test (text)
RETURNS int4
AS '$libdir/pgf1test'
LANGUAGE 'C' WITH (isStrict);

All that files worked well - I have created .so object and installed it
into /usr/local/pgsql/lib/, after that I execute pgf1test-createfunc.sql -
it's complete successfully, but
isbs=# select pgf1test('123');
ERROR: Can't find function pgf1test in file /usr/local/pgsql/lib/pgf1test.so

show errors. Why PostgreSQL can't found C-function? I know that problem
is not complex, and it's very simple question for you. Thanks.

---
best regards,
Ruslan A Dautkhanov

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2002-10-09 13:54:39 Re: Creating server-side functions: one simple error
Previous Message Ruslan A Dautkhanov 2002-10-09 06:01:48 Postmaster crash!