0

It it possible to run code that is stored in the database, on the database.

For example, I'd like a trigger to execute a function whose Javascript code is stored in the same database. (Normally, functions are defined in advance.)

Is this possible, and if so, how can I do it?

0

From https://stackoverflow.com/a/45131867/129805

You can use "eval", e.g.

create or replace function my_function()
returns text language plv8 as $$
//  load module 'test' from the table js_modules
    var res = plv8.execute("select source from js_modules where name = 'test'");
    eval(res[0].source);
//  now the function test() is defined
    return test();
$$;

select my_function();

CREATE FUNCTION
  my_function   
----------------
 this is a test
(1 row)

https://rymc.io/blog/2016/a-deep-dive-into-plv8/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.