如何与PostgreSQL进行XML规范比较? [英] How to do XML canonical comparison with PostgreSQL?

查看:132
本文介绍了如何与PostgreSQL进行XML规范比较?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将XML值与PostgreSQL 9.X进行比较。示例:

I need to compare XML values with PostgreSQL 9.X. Example:

 SELECT 1 FROM t WHERE xml1=xml2; -- error for XML datatype

时出错,但只能转换为 text 数据类型,

but can do only with casting to text datatype,

 SELECT 1 FROM t WHERE xml1::text=xml2::text; -- OK, but is a text-comparison

并不是最好的方法。我需要一个更好的比较算法...寻找它,我发现也许可以比较规范XML。

that is not the best way to do this. I need a better comparison algorithm... Looking for it, I find that, perhaps, "Canonical XML" can be compared.

如何进行规范XML比较

How to do "Canonical XML comparison" with PostgreSQL?

注意:PostgreSQL团队对XML比较抱有错误的假设吗?

NOTE: PostgreSQL team assumes false premisse about XML comparison?

许多有关XML比较的文档都认为 Canonical XML 是该操作的参考格式。例如他们说,在Wikipedia

Many documents about XML comparison sugest that Canonical XML is the reference format for that operation. Ex. at Wikipedia they say,


根据W3C,如果两个XML文档具有相同的规范形式,则这两个文档在给定的应用程序上下文中在逻辑上是等效的。

According to the W3C, if two XML documents have the same canonical form, then the two documents are logically equivalent within the given application context.

但是, PostgreSQL docs / 9.2 说,


xml数据类型很不寻常,因为它不提供任何比较运算符。这是因为没有针对XML数据的定义明确且通用的比较算法。

The xml data type is unusual in that it does not provide any comparison operators. This is because there is no well-defined and universally useful comparison algorithm for XML data.

对我来说,这是错误的前提,并且可以隐藏起来,因为它确实缺少重要的PostgreSQL问题。

Well, for me it is a false premise, and can be hiden a real lack of an important PostgreSQL issue.

推荐答案

我为PostgreSQL中的XML类型实现做出了贡献,并可能写了您引用的大多数文档。

I contributed to the XML type implementation in PostgreSQL and probably wrote most of the documentation you are citing.

当前这种方式有很多原因:

There are a number of reasons why this is currently the way it is:


  • SQL标准没有为类型<指定比较运算符code> xml 。

  • 在开始实施时,Canonical XML并未得到广泛使用和理解(至少相关人员,

  • 在XML规范化不起作用的情况下存在某些限制。尽管这些在实践中可能很少见,但这会导致无法比较数据类型的某些值的情况,例如,这将导致索引出现问题。 (出于类似的原因,为浮点类型的NaN值分配了排序位置。)

  • 通过规范化进行比较是否适合所有用途以及用户始终想要的东西,仍然值得商 li>
  • The SQL standard specifies no comparison operator for type xml.
  • At the time the implementation was started, Canonical XML wasn't widely used and understood (at least by the people involved, arguably).
  • There are certain limitations where XML canonicalization doesn't work. Although these might be rarely seen in practice, this would yield the situation where some values of a data type can't be compared, which would lead to problems with indexing for example. (The NaN value of floating-point types is assigned an ordering position for similar reasons.)
  • It's still debatable whether comparison by canonicalization is appropriate for all uses and what users always want.

当然可以欢迎实现XML规范化功能以供可选使用。实际上,我实际上希望看到一个单独的 xmlcanonical 类型,但这将需要更多工作。

An implementation of an XML canonicalization function for optional use would certainly be welcome. I would actually like to see a separate xmlcanonical type, but that would be quite a bit more work.

这篇关于如何与PostgreSQL进行XML规范比较?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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