Postgres lo_import 失败,无法打开服务器文件“\\ipaddress\test.pdf”:没有这样的文件或目录

Postgres lo_import fails with could not open server file "\\ipaddress\test.pdf": No such file or directory

我创建了 PostgreSQL 函数,它将文件路径作为输入,returns base 64 编码的文件内容。该函数在我的本地按预期工作但是当我在服务器上执行它时它给出错误 no such file or directory.

PostgreSQL 服务器安装在 Linux 服务器上,文件存在于 windows 服务器上。我正在通过从 windows 服务器连接到 PostgreSQL 来执行 select 函数(ipaddress\file-path\filename)。

create or replace function doc_import(filename text)
  returns character varying
  volatile
  language plpgsql as
$f$
    declare
        content bytea;
        loid oid;
        lfd integer;
        lsize integer;
    begin
        loid := lo_import(filename);
        lfd := lo_open(loid,262144);
        lsize := lo_lseek(lfd,0,2);
        perform lo_lseek(lfd,0,0);
        content := loread(lfd,lsize);
        perform lo_close(lfd);
        perform lo_unlink(loid);
 
         RETURN encode(content, 'base64');
    end;

lo_import是数据库服务器函数,只能从数据库服务器读取文件。您无法在 PL/pgSQL 代码中读取客户端文件。