2016-10-07 5 views
2

У меня есть это в Postgres:Postgres данные в формате XML

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'; 

Это дает мне следующее в файле output10.xml:

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

Как я могу получить это:

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

'select xmlelement (name atclist, xmlagg (xmlelement (name atccode, ...))) from ...' – Abelisto

+0

Спасибо !!! Это работает!! –

ответ

2

РЕШЕНИЕ:

COPY (SELECT xmlelement(name atclist, xmlagg(xmlelement(name atccode, 
xmlattributes(description as code), 
xmlelement(name description, description)))) 
FROM INVlist) 
TO 'path/output12.xml'; 
Смежные вопросы