query_to_xmlschema() 是一个系统函数,用于返回描述 query_to_xml() 所执行映射的 XML Schema 文档。
query_to_xmlschema() 函数在 PostgreSQL 8.3 中被添加。
用法
query_to_xmlschema (querytext,nullsboolean,tableforestboolean,targetnstext)
→xml
当提供与调用 query_to_xml() 完全相同的参数时,query_to_xmlschema() 将返回相应的 XML Schema 文档。
query_to_xml_and_xmlschema() 函数结合了这两个函数(query_to_xml() 和 query_to_xmlschema())的输出。
变更历史
- PostgreSQL 8.3
- 已添加 (commit 355e05ab)
示例
query_to_xmlschema() 的基本用法示例
postgres=# CREATE TABLE foo (id INT, val TEXT);
CREATE TABLE
postgres=# SELECT query_to_xmlschema('SELECT * FROM foo', true, true, '');
query_to_xmlschema
------------------------------------------------------------------------------------------------
<xsd:schema +
xmlns:xsd="http://www.w3.org/2001/XMLSchema"> +
+
<xsd:simpleType name="INTEGER"> +
<xsd:restriction base="xsd:int"> +
<xsd:maxInclusive value="2147483647"/> +
<xsd:minInclusive value="-2147483648"/> +
</xsd:restriction> +
</xsd:simpleType> +
+
<xsd:simpleType name="UDT.postgres.pg_catalog.text"> +
<xsd:restriction base="xsd:string"> +
</xsd:restriction> +
</xsd:simpleType> +
+
<xsd:complexType name="RowType"> +
<xsd:sequence> +
<xsd:element name="id" type="INTEGER" nillable="true"></xsd:element> +
<xsd:element name="val" type="UDT.postgres.pg_catalog.text" nillable="true"></xsd:element>+
</xsd:sequence> +
</xsd:complexType> +
+
<xsd:element name="row" type="RowType"/> +
+
</xsd:schema>
(1 row)
参考资料
- PostgreSQL 文档: 将表映射到 XML
