Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgres XML datatype

What are the benefits of using the "xml" datatype versus storing the xml content inside a "text" datatype?

Am I able to query by some specific xml attribute or element?

What about indexing and query performance?

Besides the postgresql manual what other online sources can you point me to?

like image 826
user16120 Avatar asked Apr 20 '09 17:04

user16120


1 Answers

Right now the biggest thing you get from XML fields over raw text is XPath. So if you had something similar to

CREATE TABLE pages (id int, html xml);

you could get the title of page 4 by

SELECT xpath('/html/head/title/text()', html) FROM pages WHERE id = 4;

Right now XML support is fairly limited, but got a lot better in 8.3, current docs are at link text

like image 75
Jeff Mc Avatar answered Oct 03 '22 02:10

Jeff Mc