XML(SEQUENCE)to hold arbitrary pieces of XML content, PostgreSQL provides the single
xmltype, which can hold “document” or “content”. There is no equivalent of the standard's “sequence” type.
xpath_exists()query XML documents using the XPath language. PostgreSQL also provides XPath-only variants of the standard functions
XMLTABLE, which officially use the XQuery language. For all of these functions, PostgreSQL relies on the libxml2 library, which provides only XPath 1.0.
sort, anonymous functions, and
parse-xmlto create a node from a string), but such features were not available before XPath 3.0.
sequence, which can contain XML nodes, atomic values, or both, does not exist in XPath 1.0. A 1.0 expression can only produce a node-set (containing zero or more XML nodes), or a single atomic value.
if ( hat ) then hat/@size else "no hat"has no XPath 1.0 equivalent.
"cat" < "dog"and
"cat" > "dog"are false, because each is a numeric comparison of two
NaNs. In contrast,
!=do compare the strings as strings.
sale/@hatsize = 7and
sale/@customer = "alice"are existentially quantified comparisons, true if there is any
salewith the given value for the attribute, but
sale/@taxable = false()is a value comparison to the effective boolean value of a whole node-set. It is true only if no
taxableattribute at all.
xmlvalue passed as the context item to any PostgreSQL XPath-based function must be in document form.
xmlelement), or XML to SQL (as in the output columns of
xmltable), except for a few cases treated specially, PostgreSQL simply assumes that the XML data type's XPath 1.0 string form will be valid as the text-input form of the SQL datatype, and conversely. This rule has the virtue of simplicity while producing, for many data types, results similar to the mappings specified in the standard.
BY REF, in which a particular XML value retains its node identity, and
BY VALUE, in which the content of the XML is passed but node identity is not preserved. A mechanism can be specified before a list of parameters, as the default mechanism for all of them, or after any parameter, to override the default.
xis an XML value, these two queries in an SQL:2006 environment would produce true and false, respectively:
BY REFin an
XMLTABLEconstruct, but it ignores them. The
xmldata type holds a character-string serialized representation, so there is no node identity to preserve, and passing is always effectively
xmldata type can only hold a value in
CONTENTform. An XQuery/XPath expression context item must be a single XML node or atomic value, but XPath 1.0 further restricts it to be only an XML node, and has no node type allowing
CONTENT. The upshot is that a well-formed
DOCUMENTis the only form of XML value that PostgreSQL can supply as an XPath context item.