Обсуждение: ERROR: could not find function

Поиск
Список
Период
Сортировка

ERROR: could not find function

От
vishal saberwal
Дата:
hi all,
I am having problems creating functions. Though i can still replace the already existing functions that i had created a while back in postgres 7.4.5 .Now I am running postgres 8.0.1.

The code below compiles without errrors.
gcc -Wall -I /root/postgresql-8.0.1/src/include -shared -Wl,-soname,resource_test.so.1 -o resource_test.so resource_test.c

The error is:
xy_db=# create or replace function Export_Resource_Select(text,text,text) returns text as
xy_db-# '/root/resource_test.so' language 'c';
ERROR:  could not find function "export_resource_select" in file "/root/resource_test.so"

Code:

/*
gcc -Wall -I /root/postgresql-8.0.1/src/include -shared -Wl,-soname,resource_test.so.1 -o resource_test.so resource_test.c
*/
                                                                                                                                                            
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "/usr/include/pgsql/server/postgres.h"
#include "/usr/include/pgsql/server/fmgr.h"
#include "/usr/include/pgsql/server/libpq/pqformat.h"
                                                                                                                                                            
text* Export_Resource_Select(PG_FUNCTION_ARGS);
                                                                                                                                                            
PG_FUNCTION_INFO_V1(Export_Resource_Select);
                                                                                                                                                            
text* Export_Resource_Select(PG_FUNCTION_ARGS)
{
        char *g=(char*) PG_GETARG_POINTER(0);
        char *Resource_Category=(char*) PG_GETARG_POINTER(1);
        char *Resource_Type=(char*) PG_GETARG_POINTER(2);
        char *filepath; int filelength=0;
        struct stat stat_buf;
        text* new_t;
                                                                                                                                                            
        filepath=(char *) palloc(100);
        filepath="\0";
        sprintf(filepath,"/ResourceFS/%sFS/%s/%s",Resource_Category,Resource_Type,g);
        if(!access(filepath,R_OK))
        {
                stat(filepath, &stat_buf );
                filelength=stat_buf.st_size;
        }
                                                                                                                                                            
        new_t=(text*) palloc(VARHDRSZ+strlen(filepath)+1);
        VARATT_SIZEP(new_t)=VARHDRSZ+strlen(filepath)+1;
        memcpy(VARDATA(new_t),filepath,strlen(filepath)+1);
                                                                                                                                                            
        return new_t;
}
                                                                                                                                                            
/*
create function Export_Resource_Select(varchar,varchar,varchar) returns text as
'/root/resource_test.so' language 'c';
*/

thanks,
vish

Re: ERROR: could not find function

От
vishal saberwal
Дата:
hi all,

guess i should have read the documentation more carefully.

Function was created when i did add "link_symbol" to the path.

If this is the real reason, then I believe this is something new as it used to work without using link_symbol before.

vish

On 12/12/05, vishal saberwal <vishalsaberwal@gmail.com> wrote:
hi all,
I am having problems creating functions. Though i can still replace the already existing functions that i had created a while back in postgres 7.4.5 .Now I am running postgres 8.0.1.

The code below compiles without errrors.
gcc -Wall -I /root/postgresql-8.0.1/src/include -shared -Wl,-soname,resource_test.so.1 -o resource_test.so resource_test.c

The error is:
xy_db=# create or replace function Export_Resource_Select(text,text,text) returns text as
xy_db-# '/root/resource_test.so' language 'c';
ERROR:  could not find function "export_resource_select" in file "/root/resource_test.so"

Code:

/*
gcc -Wall -I /root/postgresql-8.0.1/src/include -shared -Wl,-soname,resource_test.so.1 -o resource_test.so resource_test.c
*/
                                                                                                                                                            
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "/usr/include/pgsql/server/postgres.h"
#include "/usr/include/pgsql/server/fmgr.h"
#include "/usr/include/pgsql/server/libpq/pqformat.h"
                                                                                                                                                            
text* Export_Resource_Select(PG_FUNCTION_ARGS);
                                                                                                                                                            
PG_FUNCTION_INFO_V1(Export_Resource_Select);
                                                                                                                                                            
text* Export_Resource_Select(PG_FUNCTION_ARGS)
{
        char *g=(char*) PG_GETARG_POINTER(0);
        char *Resource_Category=(char*) PG_GETARG_POINTER(1);
        char *Resource_Type=(char*) PG_GETARG_POINTER(2);
        char *filepath; int filelength=0;
        struct stat stat_buf;
        text* new_t;
                                                                                                                                                            
        filepath=(char *) palloc(100);
        filepath="\0";
        sprintf(filepath,"/ResourceFS/%sFS/%s/%s",Resource_Category,Resource_Type,g);
        if(!access(filepath,R_OK))
        {
                stat(filepath, &stat_buf );
                filelength=stat_buf.st_size;
        }
                                                                                                                                                            
        new_t=(text*) palloc(VARHDRSZ+strlen(filepath)+1);
        VARATT_SIZEP(new_t)=VARHDRSZ+strlen(filepath)+1;
        memcpy(VARDATA(new_t),filepath,strlen(filepath)+1);
                                                                                                                                                            
        return new_t;
}
                                                                                                                                                            
/*
create function Export_Resource_Select(varchar,varchar,varchar) returns text as
'/root/resource_test.so' language 'c';
*/

thanks,
vish

Re: ERROR: could not find function

От
Martijn van Oosterhout
Дата:
On Mon, Dec 12, 2005 at 10:08:12AM -0800, vishal saberwal wrote:
> hi all,
> I am having problems creating functions. Though i can still replace the
> already existing functions that i had created a while back in postgres
> 7.4.5.Now I am running postgres
> 8.0.1.
>
> The code below compiles without errrors.
> gcc -Wall -I /root/postgresql-8.0.1/src/include -shared
> -Wl,-soname,resource_test.so.1 -o resource_test.so resource_test.c
>
> The error is:
> xy_db=# create or replace function Export_Resource_Select(text,text,text)
> returns text as
> xy_db-# '/root/resource_test.so' language 'c';
> ERROR:  could not find function "export_resource_select" in file
> "/root/resource_test.so"

The error is probably due to your function being called
"Export_Resource_Select", which is not what you told postgres. C is
absolutly not case-insensetive. So you should specify the function name
directly.

create or replace function Export_Resource_Select(text,text,text)
returns text as 'Export_Resource_Select','/root/resource_test.so' language 'c';

Have a nice day,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

Вложения