postgresql - Python can open file, PL/Python can't -


connected mydb in postgresql:

mydb=# create function file_test () returns text $$ if open('mydir/myfile.xsl'): return 'success'  $$ language plpythonu; create function mydb=# select file_test(); error:  ioerror: [errno 2] no such file or directory: 'mydir/myfile.xsl' context:  traceback (most recent call last):   pl/python function "file_test", line 2, in <module>     if open('mydir/myfile.xsl'): return 'success' pl/python function "file_test" 

over python:

>>> if open('mydir/myfile.xsl'): print 'success' ...  success >>>  

an absolute path didn't seem pl/python. i'd use postgres's query_to_xml() , run xslt transformation on return. i'll need read xsl file...

at @hruske's suggestion used plpy.notice(os.path.abspath('mydir/myfile.xsl')) see how pl/python trying resolve path. /var/lib/postgresql/9.5/main/mydir/myfile.xsl, not had in mind.

the absolute path worked after all. copying file location easier type absolute path fixed "problem."

for further reading recommend soko morinaga's novice master: ongoing lesson in extent of own stupidity.


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -