XPath sum或fn:sum函数是在PostgreSQL XPath中实现的吗? [英] Is XPath sum or fn:sum function implemented in PostgreSQL XPath?

查看:190
本文介绍了XPath sum或fn:sum函数是在PostgreSQL XPath中实现的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PostgreSQL 8.4 XPath(XML函数)功能。这是在文档中找到的经过修改的示例:

I'm using PostgreSQL 8.4 XPath (XML functions) feature. This is an adapted example found in 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']]);

此方法工作正常,它返回用 value> 15正确过滤的节点列表条件:

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

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

但是当我尝试使用 sum ,它返回一个空列表,而不是一个标量值

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

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

结果:

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

有任何建议吗?

Juan Ferreyra

Juan Ferreyra

推荐答案

xpath 不会创建新节点,它只会过滤这就是 XSLT 的目的。

xpath does not create new nodes, it only filters the currently existing ones. That's what XSLT is for.

来自 docs


函数 xpath 根据XML值 xml 计算XPath表达式 xpath 。它返回与XPath表达式生成的节点集相对应的XML值数组。

The function xpath evaluates the XPath expression xpath against the XML value xml. It returns an array of XML values corresponding to the node set produced by the XPath expression.

由于您的XPath表达式不返回节点集,因此其中没有值,也没有任何返回值。

Since your XPath expression does not return a node set, there are not values in it and there is nothing to return.

这篇关于XPath sum或fn:sum函数是在PostgreSQL XPath中实现的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆