加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

postgresql – 如何从Postgres内部列出文件夹中的文件?

发布时间:2020-12-13 18:09:42 所属栏目:百科 来源:网络整理
导读:有没有办法列出文件夹中的文件? 就像是: select * from pg_ls_dir('/home/christian') 我试过pg_ls_dir但是,per documentation: Only files within the database cluster directory and the log_directory can be accessed. Use a relative path for file
有没有办法列出文件夹中的文件?

就像是:

select * from pg_ls_dir('/home/christian')

我试过pg_ls_dir但是,per documentation:

Only files within the database cluster directory and the log_directory
can be accessed. Use a relative path for files in the cluster
directory,and a path matching the log_directory configuration setting
for log files. Use of these functions is restricted to superusers.

我需要列出postgres目录之外的文件夹中的文件,类似于COPY的操作方式.

它通常对SQL客户端没用.

无论如何,你需要实现它,这是像plperlu这样的脚本语言的典型用例.例:

CREATE FUNCTION nosecurity_ls(text) RETURNS setof text AS $$
  opendir(my $d,$_[0]) or die $!;
  while (my $f=readdir($d)) {
    return_next($f);
  }
  return undef; 
$$language plperlu;

除了限制之外,这相当于System Administration Functions中提到的pg_ls_dir(text)函数.

=> select * from nosecurity_ls('/var/lib/postgresql/9.1/main') as ls;
      ls      
-----------------
 pg_subtrans
 pg_serial
 pg_notify
 pg_clog
 pg_multixact
 ..
 base
 pg_twophase
 etc...

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读