Postgres 数据为 XML 格式

Postgres data to XML format

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

它在 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>

解决方案:

COPY (SELECT xmlelement(name atclist, xmlagg(xmlelement(name atccode,
xmlattributes(description as code), 
xmlelement(name description, description)))) 
FROM INVlist) 
TO 'path/output12.xml';