PostgreSQL 9.x-pg_read_binary_file&将文件插入bytea [英] PostgreSQL 9.x - pg_read_binary_file & inserting files into bytea
问题描述
我一直在各处(谷歌,stackoverflow等)寻找有关如何使用PostgreSQL pg_read_binary_file()
函数的一些文档。
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.
例如:
SELECT pg_read_binary_file('/some/path/and/file.gif');
ERROR: absolute path not allowed
或
SELECT pg_read_binary_file('file.gif');
ERROR: could not stat file "file.gif": No such file or directory
我需要将文件保存在特定目录中,以便Postgres可以访问它吗?如果是的话,是什么目录?
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.
推荐答案
如@a_horse_with_no_name和@guedes所述,解决方案是确保要上传的文件位于PGDATA目录中的服务器上。
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.
postgres文档确实指出
另外,我从另一个目录到PGDATA目录建立了符号链接,这样我就不会打扰任何postgres数据结构。这似乎工作得很好,我不需要执行任何疯狂的事情。
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.
这篇关于PostgreSQL 9.x-pg_read_binary_file&将文件插入bytea的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!