It's possible to call functions in another schema from within plv8 functions?

你说的曾经没有我的故事 提交于 2019-12-24 02:24:02

问题


I'm trying to use plv8 to write postgres functions. Now I would like to use the pgcrypt library in a way like this:

CREATE OR REPLACE FUNCTION v01.myfunction(arg json) 
RETURNS json AS
$BODY$
  var res;
  res = obj.crypt(arg.password, res);
  plv8.elog(NOTICE, res);
  ...

$BODY$
LANGUAGE plv8;

Where crypt comes with the pgcrypt library and is find in another schema. But if running I get the error:

ERROR:  ReferenceError: obj is not defined

Any idea? Thanks!


回答1:


It's possible to call other PLV8 functions in other schemas, yes.

You're not calling the function right though. Use

var myFunction = plv8.find_function("schemaName.functionName")

var result = myFunction();

AFAIK you can only call other PLV8 functions this way, not say PLPGSQL.

You can use plv8.execute("select someFunctionInAnotherLanguage()")




回答2:


Ok, I found it:

var pp = plv8.execute("SELECT obj.crypt($1,$2)",[arg.password, cpw]);

easy :-)



来源:https://stackoverflow.com/questions/30627205/its-possible-to-call-functions-in-another-schema-from-within-plv8-functions

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!