Im uploading an xml file in our database but i have encountered a problem I can't get multiple phone number, under child relationship of our file.
Here is my example:
CREATE TABLE test (
id int4 NOT NULL,
xml text,
CONSTRAINT pk PRIMARY KEY (id)
);
INSERT INTO test VALUES (1,
'<Agency><Key>A123</Key>
<Site>
<Key>S111</Key>
<Phone><Number>111-3456</Number><Type>Main</Type></Phone>
<Phone><Number>111-4567</Number><Type>Fax</Type></Phone>
<Phone><Number>111-4567</Number><Type>Voice</Type></Phone>
</Site>
<Site>
<Key>T222</Key>
<Phone><Number>222-5647</Number><Type>Main</Type></Phone>
<Phone><Number>222-9874</Number><Type>Fax</Type></Phone>
</Site>
<Site>
<Key>R333</Key>
<Phone><Number>222-5468</Number><Type>Main</Type></Phone>
<Phone><Number>222-2233</Number><Type>Fax</Type></Phone>
</Site>
</Agency>');
SELECT * FROM
xpath_table('id','xml','test','
/Agency/Key|/Agency/Site/Key|/Agency/Site/Phone/Number|/Agency/Site/Phone/Type','true')
as
t(id integer,agencykey text, sitekey text, phonenumber text, phonetype text);
id | agencykey | sitekey | phonenumber | phonetype
---+-----------+---------+-------------+-----------
1 | A123 | S111 | 111-3456 | Main
1 | | T222 | 111-4567 | Fax
1 | | R333 | 111-4567 | Voice
1 | | | 222-5647 | Main
1 | | | 222-9874 | Fax
1 | | | 222-5468 | Main
1 | | | 222-2233 | Fax
(7 rows)
How will I assign the sitekey to phonenumbers?
Im using PostgreSQL 8.2.11
Many Thanks,