Search code examples
postgresqlplv8

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


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!


Solution

  • Ok, I found it:

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

    easy :-)