cursor_to_xml() 是一个系统函数,用于从游标中获取行并将其映射到 XML。
cursor_to_xml() 在 PostgreSQL 8.3 中添加。
用法
cursor_to_xml (cursorrefcursor,countinteger,nullsboolean,tableforestboolean,targetnstext)
→xml
cursor 是要转换为 XML 的游标输出。请注意,如果提供 NULL,该函数将返回 NULL。
count 是要从游标返回的行数。如果游标无法返回任何行,则返回 NULL。
nulls,当设置为 true 时,将在输出中以以下方式表示 NULL 值:
<columnname xsi:nil="true"/>
如果 nulls 设置为 false,则 NULL 值将从输出中省略。
tableforest,当设置为 true 时,返回的每个列集都包装在 <table> 元素中;当设置为 false 时,返回的每个列集都包装在 <row> 元素中,而该 <row> 元素包含在一个外层的 <table> 元素中。
targetns 指定结果的 XML 命名空间。如果提供空字符串,则不使用命名空间。请注意,如果提供 NULL,则函数将返回 NULL。
变更历史
- PostgreSQL 8.3
- 已添加 (commit 355e05ab)
示例
cursor_to_xml() 的基本用法示例
postgres=# BEGIN ; BEGIN postgres=*# DECLARE foo_cursor CURSOR FOR SELECT * FROM foo; DECLARE CURSOR postgres=*# SELECT * FROM cursor_to_xml('foo_cursor', 1, false, false,''); cursor_to_xml --------------------------------------------------------------- <table xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">+ + <row> + <id>2</id> + </row> + + </table> + (1 row)
参考资料
- PostgreSQL 文档: 将表映射到 XML
