schema_to_xml_and_xmlschema() 是一个系统函数,用于将 PostgreSQL schema 的内容及其定义输出为 XML。
schema_to_xml_and_xmlschema() 函数在 PostgreSQL 8.3 中添加。
用法
schema_to_xml_and_xmlschema (schemaname,nullsboolean,tableforestboolean,targetnstext)
→xml
schema_to_xml_and_xmlschema() 结合了 schema_to_xml() 和 schema_to_xmlschema() 函数的输出。更多详细信息,请参阅每个函数的条目。
请注意,截至 PostgreSQL 16,schema_to_xml_and_xmlschema() 的输出中不包含关系定义。请参见下面的示例。
变更历史
- PostgreSQL 8.3
- 添加于 (提交 0b75afda)
示例
schema_to_xml_and_xmlschema() 的基本用法示例
postgres=# CREATE TABLE foo (id INT, val TEXT);
CREATE TABLE
postgres=# INSERT INTO foo VALUES (generate_series(1,2), clock_timestamp());
INSERT 0 2
postgres=# SELECT schema_to_xml_and_xmlschema('public', true, true, '');
schema_to_xml_and_xmlschema
------------------------------------------------------------------------------------------------------
<public xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="#"> +
+
<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:sequence> +
<xsd:element name="foo" type="RowType.postgres.public.foo" minOccurs="0" maxOccurs="unbounded"/>+
</xsd:sequence> +
</xsd:complexType> +
+
<xsd:element name="public" type="SchemaType.postgres.public"/> +
+
</xsd:schema> +
+
<foo> +
<id>2</id> +
<val xsi:nil="true"/> +
</foo> +
+
<foo> +
<id>1</id> +
<val xsi:nil="true"/> +
</foo> +
+
+
</public> +
(1 row)
参考资料
- PostgreSQL 文档: 将表映射到 XML
另请参阅
schema_to_xml(), schema_to_xmlschema(), database_to_xml_and_xmlschema(), table_to_xml_and_xmlschema(), query_to_xml_and_xmlschema(), cursor_to_xml_and_xmlschema()
