I am using PostreSQL 14.3. I am trying to put something similar to this as a PostgreSQL Function:
select xmlelement(name car, xmlforest(make, model))
from cars
and run it against a table like this:
table cars make varchar(20) model varchar(20)
data ('Dodge','Viper'), ('Ford','Thunderbird')
I am missing a root element and I cannot seem to add one.
I would like to see:
<cars>
<car><make>Dodge</make><model>Viper</model></car>
<car><make>Ford</make><model>Thunderbird</model></car>
</cars>
but what I get is:
<car><make>Dodge</make><model>Viper</model></car>
<car><make>Ford</make><model>Thunderbird</model></car>