Running system command in Postgres and use return value in Insert

早过忘川 提交于 2020-04-11 19:44:29

问题


I have a linux command that i want to run in following function:

CREATE FUNCTION tarifador_func2() RETURNS TRIGGER
LANGUAGE plsh
AS $$
#!/bin/sh
SET userid[] = // here i want to run linux command and use that return value to insert into below table
for loop with i index
INSERT INTO public.act_id_priv_mapping(id_, priv_id_, user_id_, group_id_) VALUES (auuid,new.priv_id_,userid[i],new.group_id_);
$$;

I have following values return by command with new line:

ankit
ankit1

Can anyone help me to complete my function. Thanks


回答1:


You should solve this problem differently.

Use COPY ... FROM PROGRAM to execute the shell command and populate a (temporary?) table with the result.



来源:https://stackoverflow.com/questions/61071706/running-system-command-in-postgres-and-use-return-value-in-insert

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!