From: Andrus <kobruleht2@hot.ee>
To: pgsql-general <pgsql-general@postgresql.org>
Subject: How to parse XML in Postgres newer versions also
Date: Sun, 17 Mar 2019 09:36:22 +0200
Message-ID: <DDC50001C3E84A67934B664BA564AF61@dell2> (raw)
Hi!
In Postgres 9.1.2 script below produces proper results:
1.34
5.56
In Postgres 11 it produces wrong results:
null
null
How to make it also to work in newer versions on Postgres ?
create temp table t(x xml, nsa text[][]) on commit drop;
insert into t values(
'<?xml version="1.0" encoding="UTF-8"?>
<Document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xmlns="urn:iso:std:iso:20022:tech:xsd:camt.053.001.02">
<BkToCstmrStmt>
<Stmt>
<Ntry>
<Amt Ccy="EUR">1.34</Amt>
</Ntry>
<Ntry>
<Amt Ccy="EUR">5.56</Amt>
</Ntry>
</Stmt>
</BkToCstmrStmt>
</Document> '::xml,
ARRAY[ARRAY['ns','urn:iso:std:iso:20022:tech:xsd:camt.053.001.02']]);
SELECT
(xpath('Amt/text()', x,nsa))[1]::text::numeric AS tasusumma
FROM (
SELECT unnest(xpath('/ns:Document/ns:BkToCstmrStmt/ns:Stmt/ns:Ntry',
x,nsa)) as x,
nsa
FROM t
) Ntry
Andrus.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: kobruleht2@hot.ee
Subject: Re: How to parse XML in Postgres newer versions also
In-Reply-To: <DDC50001C3E84A67934B664BA564AF61@dell2>
References: <DDC50001C3E84A67934B664BA564AF61@dell2>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox