The particular behavior for individual data types is expected to evolve in order to align the PostgreSQL mappings with those specified in SQL:2006 and later, as discussed in Section D.3.1.3.ĩ.15.1.4. Binary data (data type bytea) will be represented in base64 or hex encoding, depending on the setting of the configuration parameter xmlbinary. This means in particular that the characters, and & will be converted to entities. SELECT xmlelement(name foo, xmlattributes('xyz' as bar),Ĭontent of other types will be formatted into valid XML character data. If the content is itself of type xml, complex XML documents can be constructed. SELECT xmlelement(name test, xmlattributes(func(a, b))) FROM test Įlement content, if specified, will be formatted according to its data type. SELECT xmlelement(name test, xmlattributes('constant'), a, b) FROM test SELECT xmlelement(name test, xmlattributes(a, b)) FROM test In other cases, the attribute must be given an explicit name. SELECT xmlelement(name "foo$bar", xmlattributes('xyz' as "a&b")) Īn explicit attribute name need not be specified if the attribute value is a column reference, in which case the column's name will be used as the attribute name by default. SELECT xmlelement(name foo, xmlattributes(current_date as bar), 'cont', 'ent') Įlement and attribute names that are not valid XML names are escaped by replacing the offending characters by the sequence _x HHHH_, where HHHH is the character's Unicode codepoint in hexadecimal notation.
SELECT xmlelement(name foo, xmlattributes('xyz' as bar)) The argument(s) within XMLATTRIBUTES generate attributes of the XML element the content value(s) are concatenated to form its content. The attvalue and content items are expressions, which can yield any PostgreSQL data type. The name and attname items shown in the syntax are simple identifiers, not values. The xmlelement expression produces an XML element with the given name, attributes, and content. xmlelement xmlelement ( NAME name ) ] ] ) → xml Encoding declarations are ignored and removed in all cases.ĩ.15.1.3. If the result is determined to require a standalone declaration but no version declaration, a version declaration with version 1.0 will be used because XML requires an XML declaration to contain a version declaration. Else the result will have no standalone declaration. If all argument values have a standalone declaration value and at least one is “ no”, then that is used in the result. If all argument values have the standalone declaration value “ yes”, then that value is used in the result. If all argument values have the same XML version declaration, that version is used in the result, else no version is used.
XML declarations, if present, are combined as follows. Null values are omitted the result is only null if there are no nonnull arguments. The function xmlconcat concatenates a list of individual XML values to create a single value containing an XML content fragment.