3

I'm trying to call an external Python script file from a PostgreSQL function written in PL/Python.

My intuition drove me to code something like this :

CREATE OR REPLACE FUNCTION foo() Returns boolean AS
$$
import subprocess
cmd = "C:\\Python27\\python.exe" 
file_to_execute = "C:\\Users\\manager_gui.py"
subprocess.check_call([cmd, file_to_execute])
$$
LANGUAGE 'plpython3u' VOLATILE;

But when I execute SELECT foo() it returns me this error message :

"Command '['C:\\Python27\\python.exe', 'C:\\Users\\manager_gui.py']' returned non-zero exit status 2"

I Googled it and obviously it deals with an execution permission issue. But I'm not really sure...

So let me ask if it is really possible to do what I want to do and if I use the good method?

And if the answer is yes, how can I manage this execution permission issue between my PosgreSQL user and the owner of the script file?

Thank you in advance,

Martin

Martin Tovmassian
  • 1,010
  • 1
  • 10
  • 19
  • *"exit status 2"* usually indicates wrong command-line arguments. Perhaps `manager_gui.py` has mandatory arguments. What happens if you run it manually? – jfs Oct 21 '15 at 19:00
  • When I run it through a terminal it works. I tested my function with various script files and the error message returned is still the same... – Martin Tovmassian Oct 22 '15 at 07:52

0 Answers0