2

I have this in postgres:

copy (select  xmlelement(name atccode, xmlattributes(secondary_label as code), 
xmlelement(name description, secondary_label || ' - ' || label)) 
from study_subject where study_id=28 order by label) 
to 'includes/output10.xml';

It gives me the following in the output10.xml file:

<atccode code="6995">
  <description>6995 - Atkins, Dian</description>
</atccode>
<atccode code="130">
  <description>130 - Bailey, Howard H, MD</description>
</atccode>

How can I get this:

<atclist>
<atccode code="6995">
  <description>6995 - Atkins, Dian</description>
</atccode>
<atccode code="130">
  <description>130 - Bailey, Howard H, MD</description>
</atccode>
</atclist>
1
  • select xmlelement(name atclist, xmlagg(xmlelement(name atccode, ...))) from ... Commented Oct 7, 2016 at 18:05

1 Answer 1

2

SOLUTION:

COPY (SELECT xmlelement(name atclist, xmlagg(xmlelement(name atccode,
xmlattributes(description as code), 
xmlelement(name description, description)))) 
FROM INVlist) 
TO 'path/output12.xml';
Sign up to request clarification or add additional context in comments.

Comments

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.