PostgreSQL 9。x - pg_read_binary_file &将文件插入bytea

时间:2021-07-22 22:47:34

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

关于如何使用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? If so what directory?

我是否需要将我的文件放在一个特定的目录中,以便Postgres能够访问它?如果是什么目录?


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 个解决方案

#1


4  

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. This seems to be working well and I don't have to do any of the above crazy things.

此外,我从另一个目录创建了一个符号链接到PGDATA目录,这样就不会干扰任何postgres数据结构。这看起来运行得很好,我不需要做以上任何疯狂的事情。

#1


4  

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. This seems to be working well and I don't have to do any of the above crazy things.

此外,我从另一个目录创建了一个符号链接到PGDATA目录,这样就不会干扰任何postgres数据结构。这看起来运行得很好,我不需要做以上任何疯狂的事情。