【问题标题】:Postgres lo_import fails with could not open server file "\\ipaddress\test.pdf": No such file or directoryPostgres lo_import 失败,无法打开服务器文件“\\ipaddress\test.pdf”:没有这样的文件或目录
【发布时间】:2021-04-13 11:14:46
【问题描述】:

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

PostgreSQL 服务器安装在 Linux 服务器上,并且文件存在于 windows 服务器上。我正在通过从 windows 服务器连接到 PostgreSQL 来执行选择函数(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;

【问题讨论】:

    标签: linux postgresql server window plpgsql


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-24
      • 2018-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多