table_to_xmlschema() 是一个系统函数,它返回一个 XML Schema 文档,该文档描述了 table_to_xml() 所执行的映射。
table_to_xmlschema() 已在 PostgreSQL 8.3 中添加。
用法
table_to_xmlschema (tableregclass,nullsboolean,tableforestboolean,targetnstext)
→xml
当使用与调用 table_to_xml() 完全相同的参数调用 table_to_xmlschema() 时,它将返回相应的 XML Schema 文档。
table_to_xml_and_xmlschema() 结合了这两个函数的输出。
变更历史
- PostgreSQL 8.3
- 已添加 (commit 355e05ab)
示例
table_to_xmlschema() 的基本用法示例
postgres=# CREATE TABLE foo (id INT, val TEXT);
CREATE TABLE
postgres=# SELECT table_to_xmlschema('foo'::regclass, true, true, '');
table_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.postgres.public.foo"> +
<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="foo" type="RowType.postgres.public.foo"/> +
+
</xsd:schema>
(1 row)
参考资料
- PostgreSQL 文档: 将表映射到 XML
