Is the XPath sum or fn: sum function implemented in PostgreSQL XPath?

I am using the PostgreSQL 8.4 XPath (XML) function . This is an adapted example found in the docs:

SELECT xpath('/my:a/value[.>15]',
'<my:a xmlns:my="http://example.com">
<value>20</value>
<value>10</value>
<value>30</value>
</my:a>',
ARRAY[ARRAY['my', 'http://example.com']]);

This works fine, it returns a list of properly filtered nodes with the condition "value> 15":

xpath  
xml[]  
---------------------------------------  
"{<value>20</value>,<value>30</value>}"

But when I try to use "sum" , it returns an empty list instead of a scalar value:

SELECT xpath('sum(/my:a/value[.>15])',  
...

result:

xpath  
xml[]  
-----  
"{}"

Any suggestions?

Juan Ferreira

+3
source share
2 answers

xpathdoes not create new nodes, it only filters existing ones. This is for XSLT.

From docs :

xpath XPath xpath XML xml. XML, node, XPath.

XPath node, , .

0

, :

PostgreSQL 9.2 , xpath:

XPath , node .

, ! , : PostgreSQL 9.2. 9.2 - -, , :

postgres=# select version();
                                                     version                                                      
------------------------------------------------------------------------------------------------------------------
 PostgreSQL 9.2beta1 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-52), 64-bit
(1 row)

( Postgre 9.5, )

postgres=# SELECT xpath('sum(/my:a/value[.>15])', '<my:a xmlns:my="http://example.com">
postgres'# <value>20</value>
postgres'# <value>10</value>
postgres'# <value>30</value>
postgres'# </my:a>',
postgres(# ARRAY[ARRAY['my', 'http://example.com']]);
 xpath 
-------
 {50}
(1 row)
+1

Source: https://habr.com/ru/post/1787571/


All Articles