亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

PostgreSQL中的XML操作函數代碼

 更新時間:2009年09月06日 01:03:22   作者:  
PostgreSQL中的XML操作函數代碼

XML內容生成部分
SQL數據生成XML的函數。
1. xmlcomment:生成注釋函數。
xmlcomment(text )
例:

SELECT xmlcomment('hello');
xmlcomment
--------------
<!--hello-->

2. xmlconcat:XML連接函數
xmlconcat(xml [, ...])
例:
SELECT xmlconcat('<abc/>', '<bar>foo</bar>');

xmlconcat
----------------------
<abc/><bar>foo</bar>

連接的XML數據中如果有多個版本聲明的話,連接后的XML只有一個版本聲明。
例:
SELECT xmlconcat('<?xml version="1.1"?><foo/>', '<?xml version="1.1" standalone="no"?><bar/>');

xmlconcat
-----------------------------------
<?xml version="1.1"?><foo/><bar/>

3. xmlelement:生成XML元素函數
xmlelement(name name [, xmlattributes( value [AS attname ] [, ... ])] [ , content, ... ])
例:
SELECT xmlelement(name foo);
xmlelement
------------
<foo/>

SELECT xmlelement(name foo, xmlattributes('xyz' as bar));
xmlelement
------------------
<foo bar="xyz"/>

SELECT xmlelement(name foo, xmlattributes(current_date as bar), 'cont', 'ent');
xmlelement
-------------------------------------
<foo bar="2007-01-26">content</foo>

如果有非法字符的話,非常字符會用 16進制的數字表示出來。
例子:SELECT xmlelement(name "foo$bar", xmlattributes('xyz' as "a&b"));
xmlelement
----------------------------------
<foo_x0024_bar a_x0026_b="xyz"/>

4. xmlforest:生成XML FOREST函數
xmlforest(content [AS name ] [, ...])
例:
SELECT xmlforest('abc' AS foo, 123 AS bar);
xmlforest
------------------------------
<foo>abc</foo><bar>123</bar>

SELECT xmlforest(table_name, column_name)
FROM information_schema.columns
WHERE table_schema = 'pg_catalog';
xmlforest
-------------------------------------------------------------------------------------------
<table_name>pg_authid</table_name><column_name>rolname</column_name>
<table_name>pg_authid</table_name><column_name>rolsuper</column_name>
...
5. xmlpi:生成XML處理命令函數。
xmlpi(name target [, content ])
例:
SELECT xmlpi(name php, 'echo "hello world";');
xmlpi
-----------------------------
<?php echo "hello world";?>

6. xmlroot:修改XML值的根節(jié)點屬性函數
xmlroot(xml , version text |no value [, standalone yes|no|no value])
例子:SELECT xmlroot(xmlparse(document '<?xml version="1.1"?><content>abc</content>'),
version '1.0', standalone yes);
xmlroot
----------------------------------------
<?xml version="1.0" standalone="yes"?>
<content>abc</content>

7. xmlagg:xmlagg是集約函數
xmlagg(xml )
例:
CREATE TABLE test (y int, x xml);
INSERT INTO test VALUES (1, '<foo>abc</foo>');
INSERT INTO test VALUES (2, '<bar/>');
SELECT xmlagg(x) FROM test;
xmlagg
----------------------
<foo>abc</foo><bar/>

可以用下面類型的方法改變連接順序。
SELECT xmlagg(x) FROM (SELECT * FROM test ORDER BY y DESC) AS tab;
xmlagg
----------------------
<bar/><foo>abc</foo>

Processing XML
為了處理XML數據,PostgreSL中提供了xpath函數。
xpath(xpath , xml [, nsarray ])

例:
SELECT xpath('/my:a/text()', '<my:a xmlns:my="http://example.com">test</my:a>',
ARRAY[ARRAY['my', 'http://example.com']]);
xpath
--------
{test}
(1 row)

XML和table的映射
以下函數可以導出XML。
table_to_xml(tbl regclass, nulls boolean, tableforest boolean, targetns text)
query_to_xml(query text, nulls boolean, tableforest boolean, targetns text)
cursor_to_xml(cursor refcursor, count int, nulls boolean,
tableforest boolean, targetns text)
這些函數的返回值都是XML類型。

還有以下函數。具體內容可以參看用戶手冊。
table_to_xmlschema(tbl regclass, nulls boolean, tableforest boolean, targetns text)
query_to_xmlschema(query text, nulls boolean, tableforest boolean, targetns text)
cursor_to_xmlschema(cursor refcursor, nulls boolean, tableforest boolean, targetns text)
table_to_xml_and_xmlschema(tbl regclass, nulls boolean, tableforest boolean, targetns text)
query_to_xml_and_xmlschema(query text, nulls boolean, tableforest boolean, targetns text)
schema_to_xml(schema name, nulls boolean, tableforest boolean, targetns text)
schema_to_xmlschema(schema name, nulls boolean, tableforest boolean, targetns text)
schema_to_xml_and_xmlschema(schema name, nulls boolean, tableforest boolean, targetns text)
database_to_xml(nulls boolean, tableforest boolean, targetns text)
database_to_xmlschema(nulls boolean, tableforest boolean, targetns text)
database_to_xml_and_xmlschema(nulls boolean, tableforest boolean, targetns text)

相關文章

  • 使用PostgreSQL數據庫建立用戶畫像系統的方法

    使用PostgreSQL數據庫建立用戶畫像系統的方法

    這篇文章主要介紹了使用PostgreSQL數據庫建立用戶畫像系統,下面使用一個具體的例子來說明如何使用PostgreSQL的json數據類型來建立用戶標簽數據,需要的朋友可以參考下
    2022-10-10
  • Postgresql 動態(tài)統計某一列的某一值出現的次數實例

    Postgresql 動態(tài)統計某一列的某一值出現的次數實例

    這篇文章主要介紹了Postgresql 動態(tài)統計某一列的某一值出現的次數實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-01-01
  • PostGIS的安裝與入門使用指南

    PostGIS的安裝與入門使用指南

    在安裝PostGIS前首先必須安裝PostgreSQL,然后再安裝好的Stack?Builder中選擇安裝PostGIS組件。本文重點給大家介紹PostGIS的安裝與入門使用指南,感興趣的朋友一起看看吧
    2022-01-01
  • Windows版?PostgreSQL?利用?pg_upgrade?進行大版升級操作方法

    Windows版?PostgreSQL?利用?pg_upgrade?進行大版升級操作方法

    最近?PostgreSQL?15?版本正式發(fā)布了,新版本的各種特性和好處本文就不展開介紹了,主要介紹一下?Windows?環(huán)境下?PostgreSQL?大版本升級的方法,我們現在的幾個數據庫都是運行在?Windows服務器的?PostgreSQL?14,需要的朋友可以參考下
    2022-10-10
  • 詳解PostgreSql數據庫對象信息及應用

    詳解PostgreSql數據庫對象信息及應用

    這篇文章主要介紹了PostgreSql數據庫對象信息及應用,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-12-12
  • postgresql 如何查看pg_wal目錄下xlog文件總大小

    postgresql 如何查看pg_wal目錄下xlog文件總大小

    這篇文章主要介紹了postgresql 如何查看pg_wal目錄下xlog文件總大小的操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-01-01
  • PostgreSQL利用遞歸優(yōu)化求稀疏列唯一值的方法

    PostgreSQL利用遞歸優(yōu)化求稀疏列唯一值的方法

    這篇文章主要介紹了PostgreSQL利用遞歸優(yōu)化求稀疏列唯一值的方法,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-01-01
  • 在postgreSQL中運行sql腳本和pg_restore命令方式

    在postgreSQL中運行sql腳本和pg_restore命令方式

    這篇文章主要介紹了在postgreSQL中運行sql腳本和pg_restore命令方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-01-01
  • Postgres 創(chuàng)建Role并賦予權限的操作

    Postgres 創(chuàng)建Role并賦予權限的操作

    這篇文章主要介紹了 Postgres 創(chuàng)建Role并賦予權限的操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-01-01
  • postgresql分頁數據重復問題的深入理解

    postgresql分頁數據重復問題的深入理解

    這篇文章主要給大家介紹了關于postgresql分頁數據重復問題的相關資料,文中通過示例代碼介紹的非常詳細,對大家學習或者使用postgresql具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧
    2019-04-04

最新評論