From 9394d62c73e35329d886f96b6b000080b20132f3 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Tue, 28 Sep 1999 04:34:56 +0000 Subject: I have been working with user defined types and user defined c functions. One problem that I have encountered with the function manager is that it does not allow the user to define type conversion functions that convert between user types. For instance if mytype1, mytype2, and mytype3 are three Postgresql user types, and if I wish to define Postgresql conversion functions like I run into problems, because the Postgresql dynamic loader would look for a single link symbol, mytype3, for both pieces of object code. If I just change the name of one of the Postgresql functions (to make the symbols distinct), the automatic type conversion that Postgresql uses, for example, when matching operators to arguments no longer finds the type conversion function. The solution that I propose, and have implemented in the attatched patch extends the CREATE FUNCTION syntax as follows. In the first case above I use the link symbol mytype2_to_mytype3 for the link object that implements the first conversion function, and define the Postgresql operator with the following syntax The patch includes changes to the parser to include the altered syntax, changes to the ProcedureStmt node in nodes/parsenodes.h, changes to commands/define.c to handle the extra information in the AS clause, and changes to utils/fmgr/dfmgr.c that alter the way that the dynamic loader figures out what link symbol to use. I store the string for the link symbol in the prosrc text attribute of the pg_proc table which is currently unused in rows that reference dynamically loaded functions. Bernie Frankpitt --- src/interfaces/ecpg/preproc/preproc.y | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/interfaces') diff --git a/src/interfaces/ecpg/preproc/preproc.y b/src/interfaces/ecpg/preproc/preproc.y index 6151a6328d8..9ba3daacb64 100644 --- a/src/interfaces/ecpg/preproc/preproc.y +++ b/src/interfaces/ecpg/preproc/preproc.y @@ -799,7 +799,7 @@ adjust_array(enum ECPGttype type_enum, int *dimension, int *length, int type_dim %type opt_analyze opt_va_list va_list ExplainStmt index_params %type index_list func_index index_elem opt_type opt_class access_method_clause %type index_opt_unique IndexStmt set_opt func_return def_rest -%type func_args_list func_args opt_with ProcedureStmt def_arg +%type func_as func_args_list func_args opt_with ProcedureStmt def_arg %type def_elem def_list definition def_name def_type DefineStmt %type opt_instead event event_object RuleActionList, %type RuleActionBlock RuleActionMulti join_list @@ -2208,11 +2208,12 @@ RecipeStmt: EXECUTE RECIPE recipe_name * [, iscachable]) * [arg is ( { , })] * as + * [, ] * *****************************************************************************/ ProcedureStmt: CREATE FUNCTION func_name func_args - RETURNS func_return opt_with AS Sconst LANGUAGE Sconst + RETURNS func_return opt_with AS func_as LANGUAGE Sconst { $$ = cat2_str(cat5_str(cat5_str(make1_str("create function"), $3, $4, make1_str("returns"), $6), $7, make1_str("as"), $9, make1_str("language")), $11); } @@ -2230,6 +2231,12 @@ func_args_list: TypeId { $$ = $1; } { $$ = cat3_str($1, make1_str(","), $3); } ; +func_as: Sconst + { $$ = $1; } + | Sconst ',' Sconst + { $$ = cat3_str($1, make1_str(","), $3); } + ; + func_return: set_opt TypeId { $$ = cat2_str($1, $2); -- cgit v1.2.3