Re: [PATCHES] plperl features
Bruce Momjian wrote: Sergej, are you going to repost this patch? Sorry for delaying. Yes, I working on it, but I wait for decision about Andrew and Abhijit patches. ---(end of broadcast)--- TIP 4: Don't 'kill -9' the postmaster
Re: [PATCHES] plperl features
Sergej Sergeev [EMAIL PROTECTED] writes: What happens if you feed other pseudotypes, like cstring or language_handler? Shouldn't that be disallowed or something? Other pseudo-types are disallowed (no-change) No, because you diked out the check at lines 1452ff, rather than upgrading it to something correct. I find the fn_retispseudo and arg_is_p flags pretty bogus anyway since they fail to indicate *which* pseudotype it is. You might as well just test for the specific type OID. regards, tom lane New patch. I have added the check pseudo-type argumetns. Specific type is substituted in runtime, during function call. -- g.gRay: PL/perl, PL/PHP ;) Index: plperl.c === RCS file: /projects/cvsroot/pgsql-server/src/pl/plperl/plperl.c,v retrieving revision 1.51 diff -c -w -r1.51 plperl.c *** plperl.c13 Sep 2004 20:08:59 - 1.51 --- plperl.c30 Sep 2004 16:07:25 - *** *** 82,87 --- 82,89 boollanpltrusted; boolfn_retistuple; /* true, if function returns tuple */ boolfn_retisset;/* true, if function returns set */ + boolfn_retisarray; /* true, if function returns true array*/ + boolfn_retispseudo; /* true, if function returns pseudo type*/ Oid ret_oid;/* Oid of returning type */ FmgrInforesult_in_func; Oid result_typioparam; *** *** 89,94 --- 91,97 FmgrInfoarg_out_func[FUNC_MAX_ARGS]; Oid arg_typioparam[FUNC_MAX_ARGS]; boolarg_is_rowtype[FUNC_MAX_ARGS]; + boolarg_is_p[FUNC_MAX_ARGS]; SV *reference; } plperl_proc_desc; *** *** 277,282 --- 280,319 } /** + * convert perl array to the string representation + **/ + static SV* + plperl_convert_to_pg_array(SV *src) + { + SV* rv; + SV**val;; + AV* internal; + int len, + i; + + internal=(AV*)SvRV(src); + len = av_len(internal)+1; + + rv = newSVpv({ ,0); + for(i=0; ilen; i++) + { + val = av_fetch(internal, i, FALSE); + if (SvTYPE(*val)==SVt_RV) + if (SvTYPE(SvRV(*val))==SVt_PVAV) + sv_catpvf(rv, %s, SvPV(plperl_convert_to_pg_array(*val),PL_na)); + else + elog(ERROR, plperl: check array structure); + else + sv_catpvf(rv, %s, SvPV(*val,PL_na)); + if (i != len-1) sv_catpvf(rv, ,); + } + + sv_catpvf(rv, }); + + return rv; + } + + /** * turn a tuple into a hash expression and add it to a list **/ static void *** *** 752,757 --- 789,807 XPUSHs(sv_2mortal(newSVpv(undef, 0))); for (i = 0; i desc-nargs; i++) { + if (desc-arg_is_p[i]){ + HeapTuple typeTup; + Form_pg_typetypeStruct; + + typeTup = SearchSysCache(TYPEOID, + ObjectIdGetDatum(get_fn_expr_argtype(fcinfo-flinfo, i)), + 0, 0, 0); + typeStruct = (Form_pg_type) GETSTRUCT(typeTup); + perm_fmgr_info(typeStruct-typoutput, (desc-arg_out_func[i])); + desc-arg_typioparam[i] = getTypeIOParam(typeTup); + ReleaseSysCache(typeTup); + } + if (desc-arg_is_rowtype[i]) { if (fcinfo-argnull[i]) *** *** 909,914 --- 959,977 perlret = srf_perlret; } + if (prodesc-fn_retispseudo){ + HeapTuple retTypeTup; + Form_pg_typeretTypeStruct; + + retTypeTup = SearchSysCache(TYPEOID, + ObjectIdGetDatum(get_fn_expr_rettype(fcinfo-flinfo)), + 0, 0, 0); + retTypeStruct = (Form_pg_type) GETSTRUCT(retTypeTup); + perm_fmgr_info(retTypeStruct-typinput, (prodesc-result_in_func)); + prodesc-result_typioparam = getTypeIOParam(retTypeTup); + ReleaseSysCache(retTypeTup); + } + if (prodesc-fn_retisset SRF_IS_FIRSTCALL()) { if (prodesc-fn_retistuple
[PATCHES] plperl features
Patch provide support for array type and pseudo type (anyelement, anyarray) for function parameters and result. for example: CREATE FUNCTION add_three_values(anyelement, anyelement, anyelement) RETURNS anyelement AS ' return $_[0]+$_[1]+$_[2]; ' LANGUAGE plperl; CREATE FUNCTION make_array(anyelement, anyelement, anyelement) RETURNS anyarray AS ' return [$_[0], $_[1], $_[2]]; ' LANGUAGE plperl; Comments? --ggRay Index: plperl.c === RCS file: /projects/cvsroot/pgsql-server/src/pl/plperl/plperl.c,v retrieving revision 1.51 diff -c -w -r1.51 plperl.c *** plperl.c13 Sep 2004 20:08:59 - 1.51 --- plperl.c29 Sep 2004 15:18:29 - *** *** 82,87 --- 82,89 boollanpltrusted; boolfn_retistuple; /* true, if function returns tuple */ boolfn_retisset;/* true, if function returns set */ + boolfn_retisarray; /* true, if function returns true array*/ + boolfn_retispseudo; /* true, if function returns pseudo type*/ Oid ret_oid;/* Oid of returning type */ FmgrInforesult_in_func; Oid result_typioparam; *** *** 89,94 --- 91,97 FmgrInfoarg_out_func[FUNC_MAX_ARGS]; Oid arg_typioparam[FUNC_MAX_ARGS]; boolarg_is_rowtype[FUNC_MAX_ARGS]; + boolarg_is_p[FUNC_MAX_ARGS]; SV *reference; } plperl_proc_desc; *** *** 277,282 --- 280,319 } /** + * convert perl array to the string representation + **/ + static SV* + plperl_convert_to_pg_array(SV *src) + { + SV* rv; + SV**val;; + AV* internal; + int len, + i; + + internal=(AV*)SvRV(src); + len = av_len(internal)+1; + + rv = newSVpv({ ,0); + for(i=0; ilen; i++) + { + val = av_fetch(internal, i, FALSE); + if (SvTYPE(*val)==SVt_RV) + if (SvTYPE(SvRV(*val))==SVt_PVAV) + sv_catpvf(rv, %s, SvPV(plperl_convert_to_pg_array(*val),PL_na)); + else + elog(ERROR, plperl: check array structure); + else + sv_catpvf(rv, %s, SvPV(*val,PL_na)); + if (i != len-1) sv_catpvf(rv, ,); + } + + sv_catpvf(rv, }); + + return rv; + } + + /** * turn a tuple into a hash expression and add it to a list **/ static void *** *** 752,757 --- 789,807 XPUSHs(sv_2mortal(newSVpv(undef, 0))); for (i = 0; i desc-nargs; i++) { + if (desc-arg_is_p[i]){ + HeapTuple typeTup; + Form_pg_typetypeStruct; + + typeTup = SearchSysCache(TYPEOID, + ObjectIdGetDatum(get_fn_expr_argtype(fcinfo-flinfo, i)), + 0, 0, 0); + typeStruct = (Form_pg_type) GETSTRUCT(typeTup); + perm_fmgr_info(typeStruct-typoutput, (desc-arg_out_func[i])); + desc-arg_typioparam[i] = getTypeIOParam(typeTup); + ReleaseSysCache(typeTup); + } + if (desc-arg_is_rowtype[i]) { if (fcinfo-argnull[i]) *** *** 909,914 --- 959,977 perlret = srf_perlret; } + if (prodesc-fn_retispseudo){ + HeapTuple retTypeTup; + Form_pg_typeretTypeStruct; + + retTypeTup = SearchSysCache(TYPEOID, + ObjectIdGetDatum(get_fn_expr_rettype(fcinfo-flinfo)), + 0, 0, 0); + retTypeStruct = (Form_pg_type) GETSTRUCT(retTypeTup); + perm_fmgr_info(retTypeStruct-typinput, (prodesc-result_in_func)); + prodesc-result_typioparam = getTypeIOParam(retTypeTup); + ReleaseSysCache(retTypeTup); + } + if (prodesc-fn_retisset SRF_IS_FIRSTCALL()) { if (prodesc-fn_retistuple) *** *** 1149,1161 } else /* perl string to Datum */ retval = FunctionCall3(prodesc-result_in_func,
Re: [PATCHES] plperl features
Alvaro Herrera wrote: On Wed, Sep 29, 2004 at 07:13:47PM +0300, Sergej Sergeev wrote: Patch provide support for array type and pseudo type (anyelement, anyarray) for function parameters and result. for example: CREATE FUNCTION add_three_values(anyelement, anyelement, anyelement) RETURNS anyelement AS ' return $_[0]+$_[1]+$_[2]; ' LANGUAGE plperl; CREATE FUNCTION make_array(anyelement, anyelement, anyelement) RETURNS anyarray AS ' return [$_[0], $_[1], $_[2]]; ' LANGUAGE plperl; Comments? What happens if you feed other pseudotypes, like cstring or language_handler? Shouldn't that be disallowed or something? Other pseudo-types are disallowed (no-change) --- g.gRay: PL/perl, PL/PHP ;) ---(end of broadcast)--- TIP 6: Have you searched our list archives? http://archives.postgresql.org