diff options
| author | Bruce Momjian | 1999-09-28 04:34:56 +0000 |
|---|---|---|
| committer | Bruce Momjian | 1999-09-28 04:34:56 +0000 |
| commit | 9394d62c73e35329d886f96b6b000080b20132f3 (patch) | |
| tree | f410842b474e1ffff7cea0f89d442e8172c5c36c /src/interfaces/ecpg | |
| parent | 63a85082e32a64e2da0f3dde4e4426d016fb749e (diff) | |
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
Diffstat (limited to 'src/interfaces/ecpg')
| -rw-r--r-- | src/interfaces/ecpg/preproc/preproc.y | 11 |
1 files changed, 9 insertions, 2 deletions
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 <str> opt_analyze opt_va_list va_list ExplainStmt index_params %type <str> index_list func_index index_elem opt_type opt_class access_method_clause %type <str> index_opt_unique IndexStmt set_opt func_return def_rest -%type <str> func_args_list func_args opt_with ProcedureStmt def_arg +%type <str> func_as func_args_list func_args opt_with ProcedureStmt def_arg %type <str> def_elem def_list definition def_name def_type DefineStmt %type <str> opt_instead event event_object RuleActionList, %type <str> RuleActionBlock RuleActionMulti join_list @@ -2208,11 +2208,12 @@ RecipeStmt: EXECUTE RECIPE recipe_name * [, iscachable]) * [arg is (<type-1> { , <type-n>})] * as <filename or code in language as appropriate> + * [, <link name for dynamic loader>] * *****************************************************************************/ 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); |
