【发布时间】:2020-10-27 04:31:34
【问题描述】:
我正在使用 Postgresql 数据库。 table is ticketlines 包含一个名为 attributes 的 bytea 字段
JSON 视图中的字段内容示例:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>Ticket Attributes</comment>
<entry key="product.candiscount">true</entry>
<entry key="product.categoryid">8410a5e3-fc31-4370-b7da-d8406d80ca97</entry>
<entry key="product.kitchen">false</entry>
<entry key="product.com">false</entry>
<entry key="product.alwaysavailable">false</entry>
<entry key="product.service">true</entry>
<entry key="product.warranty">false</entry>
<entry key="product.taxcategoryid">000</entry>
<entry key="product.vprice">false</entry>
<entry key="product.discounted">no</entry>
<entry key="notes">006942</entry>
<entry key="product.texttip"/>
<entry key="product.nosc">0</entry>
<entry key="product.promotionadded">false</entry>
<entry key="product.name">Pawn Payout</entry>
<entry key="product.code">pp</entry>
<entry key="product.ispack">false</entry>
<entry key="product.alias"/>
<entry key="product.verpatrib">false</entry>
<entry key="product.managestock">true</entry>
</properties>
是否有一种简单的方法来查询此数据以在 SELECT 语句中报告(即;SELECT product.name, notes)?
我对此很接近:但显然结构错误: SELECT xpath('//properties:notes/text()', CAST(convert_from(attributes, 'UTF-8') AS XML)) FROM ticket='7abc41d9-0d7f-4187-bb81-e4139d7728bf'
结果是: 错误:无效的 XML 内容详细信息:第 2 行:StartTag:无效的元素名称 ^ *** 错误 *** 错误:无效的 XML 内容 SQL 状态:2200N 详细信息:第 2 行:StartTag:无效的元素名称
【问题讨论】:
-
“JSON”是错字吗?在我看来像 XML。
-
它来自pglobeditor.exe,xml、json和文本模式都是这样的。该应用程序在 Java 中运行,我假设 JSON 是它的完成方式。
-
XML、JSON 和文本大不相同。
-
这段文字,只是在这里展示bytea字段的内容,目的是有人协助查询字段外的数据,无意争论XML的布局差异,文本,杰森,或其他任何东西。
-
那么答案是响亮的“不”。如果未指定数据的结构,则不能期望能够从中提取元素。
标签: xml postgresql bytea