example for xmltable with XMLNAMESPACES

From: Arjen Nienhuis <a(dot)g(dot)nienhuis(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: example for xmltable with XMLNAMESPACES
Date: 2017-03-27 10:56:46
Message-ID: CAG6W84LH34k_jU4C6QVf2XdZoSHnPkGx_YO7uYh9e=JXNRsqpw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

It wasn't completely clear for me how to use namespaces in xmltable().
Maybe add this to the documentation. It shows the default namespace
and quoting the namespace name.

WITH xmldata(data) AS (VALUES ('
<example xmlns="http://example.com/myns" xmlns:B="http://example.com/b">
<item foo="1" B:bar="2"/>
<item foo="3" B:bar="4"/>
<item foo="4" B:bar="5"/>
</example>'::xml)
)
SELECT xmltable.*
FROM XMLTABLE(XMLNAMESPACES('http://example.com/myns' AS x,
'http://example.com/b' AS "B"),
'/x:example/x:item'
PASSING (SELECT data FROM xmldata)
COLUMNS foo int PATH '@foo',
bar int PATH '@B:bar');
foo | bar
-----+-----
1 | 2
3 | 4
4 | 5
(3 rows)

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2017-03-27 10:57:56 Re: [POC] A better way to expand hash indexes.
Previous Message Rafia Sabih 2017-03-27 10:49:37 Re: pgbench - allow to store select results into variables