0

I have a xml file which has array attributes and normal attribute. I need to store these array attributes and normal values into a postgresql table.

-<sample-test>
     <BookerNo>50105</BookerNo>
     <Type>
         <V Idx="1">A</V>
         <V Idx="2">B</V>
     </Type>
     <Value>
         <V Idx="1">50108</V>
         <V Idx="2">50158</V>
     </Value>
</sample-test>
-<sample-test>
     <BookerNo>50106</BookerNo>
     <Type>
         <V Idx="1">A</V>
         <V Idx="2">B</V>
         <V Idx="3">C</V>
     </Type>
     <Value>
         <V Idx="1">60108</V>
         <V Idx="2">60135</V>
         <V Idx="3">60158</V>
     </Value>
</sample-test>

Table name sample

col1    col2    col3   col4
1      50105     A     50108
2      50105     B     50158
3      50106     A     60108
4      50106     B     60135
5      50106     C     60158
3
  • See Extract data from a Postgres XML column using XPath Commented Apr 25, 2019 at 14:59
  • Thanks Klin for the response. But it is not working in my situation since my file is xmlns file eg <sample-test xmlns="dmotorworks.com/sample-test"> Commented Apr 26, 2019 at 12:31
  • You have to have the data in the database to use Postgres function xpath(). You can import the file to a temp table using COPY command. Alternatively, you can parse the xml file with e.g. python script and one of its xml parsers. Commented Apr 26, 2019 at 13:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.