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
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)
answered Jan 13, 2022 at 10:05
lang-sql