在桌面 PostgreSQL 中使用 pg_read_file 读取文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22074987/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
using pg_read_file read file in desktop PostgreSQL
提问by Arjun Raj
I wanted to how to read a file in my desk top using pg_read_filein PostgreSQL
我想如何使用阅读我的桌面文件pg_read_file在 PostgreSQL的
pg_read_file(filename text [, offset bigint, length bigint])
pg_read_file(文件名文本 [,偏移量 bigint,长度 bigint])
my query
我的查询
select pg_read_file('/root/desktop/new.txt' , 0 , 1000000);
error
错误
ERROR: absolute path not allowed
回答by Houari
pg_read_filecan read the files only from the data directory path, if you would like to know your data directory path use:
pg_read_file只能从数据目录路径中读取文件,如果您想知道您的数据目录路径,请使用:
SHOW data_directory;
I think that you can resolve you problem by looking to this post
我认为你可以通过查看这篇文章来解决你的问题
回答by Craig Ringer
If you're using psql
you can use \lo_import
to create a large object from a local file.
如果您正在使用,psql
您可以使用\lo_import
从本地文件创建一个大对象。
The pg_read_file
tool only allows reads from server-sidefiles.
该pg_read_file
工具只允许从服务器端文件读取。
回答by chetan chadha
lo_import(file path) will generate an oid.This may solve your problem. you can import any type of file using this (even image)
lo_import(file path) 将生成一个oid。这可能会解决您的问题。您可以使用此(甚至图像)导入任何类型的文件