2017-10-14 5 views
1

を実行するためにシステムコールを使用してPostgreSQLでC関数を実行できませんでした私は、次のしている:はPythonスクリプト

/* execute_py.c */ 
#include <stdio.h> 
#include <stdlib.h> 
#include "postgres.h" 
#include "fmgr.h" 

#ifdef PG_MODULE_MAGIC 
PG_MODULE_MAGIC; 
#endif 

int 
call_py() 
{ 
     printf("Executing your Python script..."); 
     return system("python36 absolute/path/to/example.py"); 
} 

と:

# example.py 
with open("absolute/path/to/test.txt", "w") as f: 
    f.write("hello world") 

私はその後、作成したexecute_py.oexecute_py.soにCスクリプトをコンパイルPostgreSQLサーバの機能:

CREATE OR REPLACE FUNCTION call_py() RETURNS integer 
    AS 'absolute/path/to/execute_py', 'call_py' 
    LANGUAGE C STRICT; 

このような関数:

SELECT call_py(); 

関数が0を返した。しかし、私はフォルダをチェックすると、生成されているいかなるtest.txtはありません。

私はCが新しく、何が起こったのかよくわかりません。助けを求める。

ありがとうございます!

答えて

1

申し訳ありません、私は愚かで、実行許可をexample.pyに追加するのを忘れていました。