Does XMLSERIALIZE output xmlattributes in a stable order? - Mailing list pgsql-hackers

From Chapman Flack
Subject Does XMLSERIALIZE output xmlattributes in a stable order?
Date
Msg-id 62ce7506-b315-d358-97dd-48846baeade8@anastigmatix.net
Whole thread Raw
Responses Re: Does XMLSERIALIZE output xmlattributes in a stable order?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Suppose I have a query that generates some XML content, and I want
to do this on a periodic schedule and check the resulting XML into
a version control system.

To avoid spurious diffs, I know I can control the order of child
elements generated by xmlagg by slipping an ORDER BY into the
aggregate expression.

But then, there are the attributes of elements. Order of attributes
is not significant in XML, and is not required (by the "XML Infoset"
standard) to be preserved. Nevertheless, it would be a useful
property (for a purpose like I've described) if XMLSERIALIZE were
known to at least produce the attributes in some consistent order
across evaluations of the same query.

Is that true of the implementation in PostgreSQL? I might find out
with a quick test, but it seemed worth explicitly asking.

This is subtle enough that, if it's true, it is probably worth
mentioning in the docs. (If it isn't true, it might even be worth
making it true, then mentioning it in the docs.) While [XML Infoset]
does say that an element's attributes are an "unordered set",
[XQuery and XPath Data Model (XDM)] says "the order of Attribute Nodes
is stable but implementation dependent", and it's the latter document
that's referenced by [XSLT and XQuery Serialization], which is the
standard upon which XMLSERIALIZE is defined in [SQL/XML]. (Phew!)

-Chap


pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: Treating work_mem as a shared resource (Was: Parallel Hash take II)
Next
From: Merlin Moncure
Date:
Subject: Re: feature request: consume asynchronous notification via a function