Use of JavaScript in PG requires the use of plv8 extension
Need to open the extension
create extension plv8;
Create function template
create or replace function function_name()
returns void as $$
// V8 Javascript
// 在这里写 Javascript Code
$$ language plv8;
Run if you execute
select function_name();
plv8 helloworld example
create or replace function hello_world(name text)
returns text as $$
let output = `Hello, ${name}!`;
return output;
$$ language plv8;
Execute sql use plv8.execute
function
create or replace function update_user(id bigint, first_name text)
returns smallint as $$
var num_affected = plv8.execute(
'update profiles set first_name = $1 where id = $2',
[first_name, id]
);
return num_affected;
$$ language plv8;
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。