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.o
とexecute_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が新しく、何が起こったのかよくわかりません。助けを求める。
ありがとうございます!