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?

asked Jan 13, 2022 at 9:59

1 Answer 1

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/

answered Jan 13, 2022 at 10:05

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.