PostgreSQL 9.x - pg_read_binary_file & inserting files into bytea

不问归期 提交于 2019-12-11 01:57:02

问题


I have been looking everywhere (google, stackoverflow, etc.) for some documentation on how to use the PostgreSQL pg_read_binary_file() function.

The only meaningful thing I can find is this page in the official documentation.

Every time I try to use this function I get an error.

For example:

    SELECT pg_read_binary_file('/some/path/and/file.gif');
    ERROR:  absolute path not allowed

or

    SELECT pg_read_binary_file('file.gif');
    ERROR:  could not stat file "file.gif": No such file or directory

Do I need to have my file in a specific directory for Postgres to have access to it? If so what directory?


If it matters, the reason I am looking at this function is because I am trying to insert a file into the database without doing crazy things.


回答1:


As stated by @a_horse_with_no_name and @guedes the solution is to ensure that the file being uploaded is on the server in the PGDATA directory.

The postgres documentation does state the file location as a requirement.

Additionally, I made a symlink from another directory to the PGDATA directory so that I would not disturb any of the postgres data structure. This seems to be working well and I don't have to do any of the above crazy things.



来源:https://stackoverflow.com/questions/16048649/postgresql-9-x-pg-read-binary-file-inserting-files-into-bytea

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!