在 Postgres 中运行系统命令并在 Insert 中使用返回值 [英] Running system command in Postgres and use return value in Insert

查看:75
本文介绍了在 Postgres 中运行系统命令并在 Insert 中使用返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要在以下函数中运行的 linux 命令:

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

推荐答案

你应该以不同的方式解决这个问题.

You should solve this problem differently.

使用 COPY ... FROM PROGRAM 执行 shell 命令并用结果填充(临时?)表.

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

这篇关于在 Postgres 中运行系统命令并在 Insert 中使用返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆