Can you run PL/Python or PL/v8 code from the database itself?



  • 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?



  • 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/




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2