CREATE OR REPLACE FUNCTION j_f_sync_from_xml_2()
RETURNS boolean AS
$BODY$
DECLARE
myxml xml;
datafile text := 'ABBATE_EMANUELE_Lvl1F2Va_20160418-1759_3.xml';
BEGIN
myxml := pg_read_file(datafile, 0, 100000000);
CREATE TABLE public.james_2 AS
SELECT unnest(xpath('//@OPERATORE', t)) as Operatore,
unnest(xpath('//@DATA', t)) as Data, unnest(xpath('//ObjectSelect/@NOME',
t)) as Nome, unnest(xpath('//ObjectSelect/@TEMPO', t)) as Tempo,
unnest(xpath('//ObjectSelect/@X', t)) as X,
unnest(xpath('//ObjectSelect/@Y', t)) as Y,
unnest(xpath('//ObjectSelect/@Z', t)) as Z
FROM unnest(xpath('/root/level', myxml)) x(t);
RETURN TRUE;
END;
$BODY$ language plpgsql;
此程序将列创建为XML类型。 如何将XML类型转换为整数格式? 我试过这段代码:
select Tempo::text::int
from james_2
cross join lateral
unnest(xpath('//ObjectSelect/@TEMPO', Tempo)) xp(T)
但是给我一个错误:<找不到
答案 0 :(得分:0)
您正在尝试转换进入xpath调用的完整xml,而不是将别名为xp(T)的最终输出。我希望
select T::text::int
from james_2
cross join lateral
unnest(xpath('//ObjectSelect/@TEMPO', Tempo)) xp(T)
上班。 ::text::int
演员是我在类似情况下使用它的正确理念。