第 7 行不允许绝对路径 xml 到 postgres?

Absolute path not allowed on row 7, xml to postgres?

CREATE OR REPLACE FUNCTION j_f_sync_from_xml()
RETURNS boolean AS
$BODY$
DECLARE
myxml    xml;
datafile text := 
'C:\Users\Polichetti\Documents\ABBATE_EMANUELE_Lvl1F2Va_20160418-1759.xml';
BEGIN

myxml := pg_read_file(datafile, 0, 100000000); 

CREATE TABLE james AS
SELECT (xpath('//some_id/text()', x))[1]::text AS id
FROM   unnest(xpath('/xml/path/to/datum', myxml)) x;
END;
$BODY$ language plpgsql;
SELECT * from james;

我发现一个错误,第 7 行不允许使用绝对路径。 可能我不知道我必须使用哪条路径。

https://www.postgresql.org/docs/current/static/functions-admin.html#FUNCTIONS-ADMIN-GENFILE

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.

您可以访问任何 OS 文件,运行 show data_directoryshow log_directory o 找出可以使用 pg_read_file[=17 读取文件的位置=]

如果你想加载 xml 到数据库,我宁愿使用不同的方法,例如:

create table xml(body text);
copy xml from '/absolute/path/to/file.xml';
select string_agg(body,'')::xml from xml;

这是最简单的示例。您可以在网上查看更多信息,例如 using large objects utils