Here is example table used for getting some basic operations with xml column in postgreSQL table.
DROP TABLE IF EXISTS temp1;
CREATE TABLE temp1(myindex serial PRIMARY KEY, description xml);
INSERT INTO temp1(description)
VALUES
('<?xml version="1.0" encoding="utf-8"?>
<setup xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<DATABASE>herdatabase</DATABASE>
<DBSERVER>127.0.0.1</DBSERVER>
<DBUSER>saly</DBUSER>
<DBPORT>5432</DBPORT>
</setup>'),
('<?xml version="1.0" encoding="utf-8"?>
<setup xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<DATABASE>mydatabase</DATABASE>
<DBSERVER>127.0.0.1</DBSERVER>
<DBUSER>john</DBUSER>
<DBPORT>4424</DBPORT>
</setup>');
I decided to use XML instead of hstore and JSON since I'm working in .NET where XML functions and serialization is well supported and I haven't much of such data so speed is not much important.
From here I try some basic queries to get data.
--1) That one work
SELECT xpath('/setup/DBPORT/text()', description) FROM temp1;
--2) That work but give two arrays with single value
-- How to get one array with 2 values like "{5432, 127.0.0.1}"
SELECT xpath('/setup/DBPORT/text()', description), xpath('/setup/DBSERVER/text()', description) FROM temp1;
--3) How to get description when condition is met?
-- Here I get ERROR: could not identify an equality operator for type xml
SELECT description FROM temp1 WHERE xpath('/setup/DBSERVER/text()', description) = '{127.0.0.1}';
--4) How to get all values when condition is met?
SELECT allvalues FROM temp1 WHERE xpath('/setup/DBUSER/text()', description) = 'john';
How to get working those queries which don't work?