schema_to_xmlschema() 是一个系统函数,它返回一个XML Schema文档,该文档描述了schema_to_xml()执行的映射。
schema_to_xmlschema() 已在 PostgreSQL 8.3 中添加。
用法
schema_to_xmlschema (schemaname,nullsboolean,tableforestboolean,targetnstext)
→xml
当使用与调用schema_to_xml()完全相同的参数调用schema_to_xmlschema()时,它将返回相应的XML Schema文档。
请注意,截至 PostgreSQL 16,生成的XML schema不描述schema中的所有对象。在下面的示例中,描述了表和使用的数据类型,但没有描述单个表行的组成。
变更历史
- PostgreSQL 8.3
- 添加于 (提交 0b75afda)
示例
schema_to_xmlschema() 的基本用法示例
postgres=# CREATE TABLE foo (id INT, val TEXT);
CREATE TABLE
postgres=# CREATE TABLE bar (id INT, val TEXT);
CREATE TABLE
postgres=# SELECT schema_to_xmlschema('public', true, false, '');
schema_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="SchemaType.postgres.public"> +
<xsd:all> +
<xsd:element name="bar" type="TableType.postgres.public.bar"/>+
<xsd:element name="foo" type="TableType.postgres.public.foo"/>+
</xsd:all> +
</xsd:complexType> +
+
<xsd:element name="public" type="SchemaType.postgres.public"/> +
+
</xsd:schema>
(1 row)
参考资料
- PostgreSQL 文档: 将表映射到 XML
