scott@[local]:5432:scottdb]
SQL> create table t_xml(id int, val xml); -- 오라클 처럼 XML 을 저장하기 위한 데이터 타입이 별도로 존재합니다.
CREATE TABLE
scott@[local]:5432:scottdb]
SQL> insert into t_xml(id,val) values(0,'<site><admin>PostgresDBA</admin><url>http://www.postgresdba.com</url></site>');
INSERT 0 1
SQL>
scott@[local]:5432:scottdb]
SQL> select * from t_xml;
id | val
----+------------------------------------------------------------------------------
0 | <site><admin>PostgresDBA</admin><url>http://www.postgresdba.com</url></site>
(1 row)
SQL> select xpath('//admin/text()',val) from t_xml; -- 값을 배열로 반환하는 군요.
xpath
---------------
{PostgresDBA}
(1 row)
scott@[local]:5432:scottdb]
SQL> select xpath('//url/text()',val) from t_xml;
xpath
------------------------------
{http://www.postgresdba.com}
(1 row)
scott@[local]:5432:scottdb]
SQL> select (xpath('//admin/text()',val))[1]::text from t_xml; -- 배열원소값을 가져옵니다.
xpath
-------------
PostgresDBA
(1 row)
scott@[local]:5432:scottdb]
SQL> select (xpath('//url/text()',val))[1]::text from t_xml;
xpath
----------------------------
http://www.postgresdba.com
(1 row)
scott@[local]:5432:scottdb]
SQL>
이상으로 아주 간단하게 XML 을 다뤄봤습니다.
XML 을 많이 쓰시는 분은 많은 XML 함수들이 있으니 매뉴얼을 꼭 찾아보세요.