Hi All,

(1) I have written the following test function with
intention to experiment how extending a function works
in postgreSQL.

//func.c

#include "postgres.h"
#include <string.h>
#include "fmgr.h"

PG_FUNCTION_INFO_V1(MyInc);

Datum MyInc(PG_FUNCTION_ARGS)
{
	int32 arg = PG_GETARG_INT32(0);
	PG_RETURN_INT32(arg+1);
}

// I compiled it and made a .so file and placed it in
pgsql/lib directory which is my default
dynamic_library_path

(2) Then I made the following entry in pg_proc.h
 
DATA(insert OID = 4000 (  MyInc			PGUID 12 f t t t 1 f
23 "23" 100 0 0 100  MyInc testfunc ));
DESCR("test function ");

(3) I included the pg_proc.h file in
src/include/catalog
and then I executed gmake from 
src/backend/catalog 
directory

I encountered the following problem

PROBLEM 1:

(4) the compiled postgres.bki file has the entries
with ';' like (I am showing one of the places where
the ';' is placed )

// First

# PostgreSQL 7.2
# 1 "/tmp/genbkitmp.c"
create bootstrap pg_proc
 (
 proname;^M = name ,

and like that

//Second

'));' remains from the DATA() entry in pg_proc.h
like

insert OID = 4000 ( MyInc 1 12 f t t t 1 f 23 "23" 100
0 0 100 MyInc func ));

Hence I have to remove these semicolon manually form
postgres.bki file and had to place manually in the
pgsql/share directory from where the initdb reads this
file.

PROBLEM 2:

(5) And when I run the following query 
    
test=# select MyInc(6);

Following error came

ERROR:  Function 'myinc(int4)' does not exist
        Unable to identify a function that satisfies
the given argument types
        You may need to add explicit typecasts

PROBLEM 3:

I didn't get a way to reflect all the new DATA()
entries in pg_proc.h to pg_proc system table without
deleting the "data" directory and reinitializing it
again by running "initdb".


(6) Kindly guide me how should I rectify these
problem?

Thanks in advance for your help and time

Regards
Amit Khare



__________________________________________________
Do You Yahoo!?
Try FREE Yahoo! Mail - the world's greatest free email!
http://mail.yahoo.com/

Sat, 9 Mar 2002 10:10:24 -0800 (PST)
Amit Kumar Khare <skamit2000@yahoo.com>
Error in executing user defined function
Amit Kumar Khare <skamit2000@yahoo.com> writes:
> (2) Then I made the following entry in pg_proc.h
 
> DATA(insert OID = 4000 (  MyInc			PGUID 12 f t t t 1 f
> 23 "23" 100 0 0 100  MyInc testfunc ));
> DESCR("test function ");

I think you ignored the advice that appears at the head of pg_proc.h
(and all the other include/catalog headers):

 *	  XXX do NOT break up DATA() statements into multiple lines!
 *		  the scripts are not as smart as you might think...
 *	  XXX (eg. #if 0 #endif won't do what you think)

> PROBLEM 3:

> I didn't get a way to reflect all the new DATA()
> entries in pg_proc.h to pg_proc system table without
> deleting the "data" directory and reinitializing it
> again by running "initdb".

Quite.  CREATE FUNCTION is the usual way of creating new pg_proc entries
on-the-fly.  The include/catalog files contain exactly those entries
that are inserted by initdb; there is no other path from them to the
running system.

			regards, tom lane

Sat, 09 Mar 2002 13:38:01 -0500
Tom Lane <tgl@sss.pgh.pa.us>
Re: Error in executing user defined function 