简体   繁体   English

PostgreSQL 9.x-pg_read_binary_file并将文件插入bytea

[英]PostgreSQL 9.x - pg_read_binary_file & inserting files into bytea

I have been looking everywhere (google, stackoverflow, etc.) for some documentation on how to use the PostgreSQL pg_read_binary_file() function. 我一直在各处(google,stackoverflow等)寻找有关如何使用PostgreSQL pg_read_binary_file()函数的一些文档。

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? 我需要将文件保存在特定目录中,以便Postgres可以访问它吗? 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 . 如果很重要,我查看此功能的原因是因为我试图在不做疯狂事情的情况下将文件插入数据库。

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. 如@a_horse_with_no_name和@guedes所述,解决方案是确保要上载的文件在PGDATA目录中的服务器上。

The postgres documentation does state the file location as a requirement. 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. 另外,我从另一个目录到PGDATA目录建立了符号链接,这样我就不会打扰任何postgres数据结构。 This seems to be working well and I don't have to do any of the above crazy things . 这似乎运行良好,我不必做以上疯狂的事情

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM