diff --git a/doc/src/sgml/datatype.sgml b/doc/src/sgml/datatype.sgml
index b81d89e26080..a41492f357e1 100644
--- a/doc/src/sgml/datatype.sgml
+++ b/doc/src/sgml/datatype.sgml
@@ -4518,7 +4518,10 @@ xml 'bar'
xml, uses the function
xmlserialize:xmlserialize
-XMLSERIALIZE ( { DOCUMENT | CONTENT } value AS type [ [ NO ] INDENT ] )
+XMLSERIALIZE ( { DOCUMENT | CONTENT } value AS type
+ [ VERSION xmlversion ]
+ [ INCLUDING XMLDECLARATION | EXCLUDING XMLDECLARATION ]
+ [ [ NO ] INDENT ] )
type can be
character, character varying, or
@@ -4528,6 +4531,40 @@ XMLSERIALIZE ( { DOCUMENT | CONTENT } value AS
+
+ The VERSION option sets the version string
+ used in the XML declaration. If specified, the value of
+ xmlversion must conform to the lexical
+ rules of the XML standard: it must be a string of the form
+ '1.' followed by one or more digits (e.g.,
+ '1.0', '1.1'). Versions other
+ than 1.x (e.g., '2.0') are not valid in
+ DOCUMENT mode and will result in an error. This format
+ is defined in section 2.8,
+ "Prolog and Document Type Declaration",
+ of the XML standard. If the VERSION option is omitted or specified as
+ NULL, version 1.0 is used by default.
+
+ In CONTENT mode, no validation is performed on the version,
+ and it is emitted as specified if an XML declaration is requested.
+
+
+
+ The INCLUDING XMLDECLARATION and
+ EXCLUDING XMLDECLARATION options control
+ whether the serialized output includes an XML declaration such as
+ <?xml version="1.0" encoding="UTF-8"?>.
+ If neither option is specified, the presence of the declaration in
+ the output depends on whether the input value
+ originally contained one.
+
+ The INCLUDING XMLDECLARATION option is allowed in both
+ DOCUMENT and CONTENT modes. In
+ CONTENT mode, no structural validation is performed,
+ and the declaration is emitted according to the specified options,
+ even if it would not normally be considered valid by the XML specification.
+
+
The INDENT option causes the result to be
pretty-printed, while NO INDENT (which is the
@@ -4535,6 +4572,36 @@ XMLSERIALIZE ( { DOCUMENT | CONTENT } value AS
+
+Examples:
+
++
+ +
+ 42 +
+
+(1 row)
+
+SELECT
+ xmlserialize(
+ DOCUMENT '42' AS text
+ EXCLUDING XMLDECLARATION);
+
+ xmlserialize
+--------------------------
+ 42
+(1 row)
+]]>
+
When a character string value is cast to or from type
xml without going through XMLPARSE or
diff --git a/src/backend/catalog/sql_features.txt b/src/backend/catalog/sql_features.txt
index 3a8ad201607f..d7454df3adbc 100644
--- a/src/backend/catalog/sql_features.txt
+++ b/src/backend/catalog/sql_features.txt
@@ -665,9 +665,9 @@ X072 XMLSerialize: character string serialization YES
X073 XMLSerialize: binary string serialization and CONTENT option NO
X074 XMLSerialize: binary string serialization and DOCUMENT option NO
X075 XMLSerialize: binary string serialization NO
-X076 XMLSerialize: VERSION NO
+X076 XMLSerialize: VERSION YES
X077 XMLSerialize: explicit ENCODING option NO
-X078 XMLSerialize: explicit XML declaration NO
+X078 XMLSerialize: explicit XML declaration YES
X080 Namespaces in XML publishing NO
X081 Query-level XML namespace declarations NO
X082 XML namespace declarations in DML NO
diff --git a/src/backend/executor/execExprInterp.c b/src/backend/executor/execExprInterp.c
index 0e1a74976f7d..598c1b7ac313 100644
--- a/src/backend/executor/execExprInterp.c
+++ b/src/backend/executor/execExprInterp.c
@@ -4621,7 +4621,9 @@ ExecEvalXmlExpr(ExprState *state, ExprEvalStep *op)
*op->resvalue =
PointerGetDatum(xmltotext_with_options(DatumGetXmlP(value),
xexpr->xmloption,
- xexpr->indent));
+ xexpr->indent,
+ xexpr->xmldeclaration,
+ xexpr->version));
*op->resnull = false;
}
break;
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index a4b29c822e8f..43a990b9208c 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -626,6 +626,8 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
%type xmltable_column_option_el
%type xml_namespace_list
%type xml_namespace_el
+%type opt_xml_declaration_option
+%type opt_xml_declaration_version xmlserialize_version
%type func_application func_expr_common_subexpr
%type func_expr func_expr_windowless
@@ -794,8 +796,8 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
WHEN WHERE WHITESPACE_P WINDOW WITH WITHIN WITHOUT WORK WRAPPER WRITE
- XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLEXISTS XMLFOREST XMLNAMESPACES
- XMLPARSE XMLPI XMLROOT XMLSERIALIZE XMLTABLE
+ XML_P XMLATTRIBUTES XMLCONCAT XMLDECLARATION XMLELEMENT XMLEXISTS XMLFOREST
+ XMLNAMESPACES XMLPARSE XMLPI XMLROOT XMLSERIALIZE XMLTABLE
YEAR_P YES_P
@@ -16200,14 +16202,16 @@ func_expr_common_subexpr:
$$ = makeXmlExpr(IS_XMLROOT, NULL, NIL,
list_make3($3, $5, $6), @1);
}
- | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename xml_indent_option ')'
+ | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename opt_xml_declaration_version opt_xml_declaration_option xml_indent_option ')'
{
XmlSerialize *n = makeNode(XmlSerialize);
n->xmloption = $3;
n->expr = $4;
n->typeName = $6;
- n->indent = $7;
+ n->version = $7;
+ n->xmldeclaration = $8;
+ n->indent = $9;
n->location = @1;
$$ = (Node *) n;
}
@@ -16432,6 +16436,21 @@ xml_indent_option: INDENT { $$ = true; }
| /*EMPTY*/ { $$ = false; }
;
+xmlserialize_version:
+ VERSION_P Sconst { $$ = $2; }
+ | VERSION_P NULL_P { $$ = NULL; }
+ ;
+
+opt_xml_declaration_version:
+ xmlserialize_version { $$ = $1; }
+ | /*EMPTY*/ { $$ = NULL; }
+ ;
+
+opt_xml_declaration_option: INCLUDING XMLDECLARATION { $$ = XMLSERIALIZE_INCLUDING_XMLDECLARATION; }
+ | EXCLUDING XMLDECLARATION { $$ = XMLSERIALIZE_EXCLUDING_XMLDECLARATION; }
+ | /*EMPTY*/ { $$ = XMLSERIALIZE_NO_XMLDECLARATION_OPTION; }
+ ;
+
xml_whitespace_option: PRESERVE WHITESPACE_P { $$ = true; }
| STRIP_P WHITESPACE_P { $$ = false; }
| /*EMPTY*/ { $$ = false; }
@@ -18126,6 +18145,7 @@ unreserved_keyword:
| WRAPPER
| WRITE
| XML_P
+ | XMLDECLARATION
| YEAR_P
| YES_P
| ZONE
@@ -18784,6 +18804,7 @@ bare_label_keyword:
| XML_P
| XMLATTRIBUTES
| XMLCONCAT
+ | XMLDECLARATION
| XMLELEMENT
| XMLEXISTS
| XMLFOREST
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 12119f147fc1..19938271adf9 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -2502,6 +2502,8 @@ transformXmlSerialize(ParseState *pstate, XmlSerialize *xs)
xexpr->xmloption = xs->xmloption;
xexpr->indent = xs->indent;
+ xexpr->version = xs->version;
+ xexpr->xmldeclaration = xs->xmldeclaration;
xexpr->location = xs->location;
/* We actually only need these to be able to parse back the expression. */
xexpr->type = targetType;
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 79ec136231be..050e327e5ba0 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -10232,6 +10232,15 @@ get_rule_expr(Node *node, deparse_context *context,
appendStringInfo(buf, " AS %s",
format_type_with_typemod(xexpr->type,
xexpr->typmod));
+
+ if (xexpr->version)
+ appendStringInfo(buf, " VERSION '%s'", xexpr->version);
+
+ if (xexpr->xmldeclaration == XMLSERIALIZE_INCLUDING_XMLDECLARATION)
+ appendStringInfoString(buf, " INCLUDING XMLDECLARATION");
+ else if (xexpr->xmldeclaration == XMLSERIALIZE_EXCLUDING_XMLDECLARATION)
+ appendStringInfoString(buf, " EXCLUDING XMLDECLARATION");
+
if (xexpr->indent)
appendStringInfoString(buf, " INDENT");
else
diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c
index 35c915573a1d..b025f27a66d6 100644
--- a/src/backend/utils/adt/xml.c
+++ b/src/backend/utils/adt/xml.c
@@ -152,7 +152,8 @@ static xmlChar *xml_text2xmlChar(text *in);
static int parse_xml_decl(const xmlChar *str, size_t *lenp,
xmlChar **version, xmlChar **encoding, int *standalone);
static bool print_xml_decl(StringInfo buf, const xmlChar *version,
- pg_enc encoding, int standalone);
+ pg_enc encoding, int standalone,
+ bool force_xmldeclaration);
static bool xml_doctype_in_content(const xmlChar *str);
static xmlDocPtr xml_parse(text *data, XmlOptionType xmloption_arg,
bool preserve_whitespace, int encoding,
@@ -325,7 +326,7 @@ xml_out_internal(xmltype *x, pg_enc target_encoding)
initStringInfo(&buf);
- if (!print_xml_decl(&buf, version, target_encoding, standalone))
+ if (!print_xml_decl(&buf, version, target_encoding, standalone, false))
{
/*
* If we are not going to produce an XML declaration, eat a single
@@ -619,7 +620,8 @@ xmlconcat(List *args)
print_xml_decl(&buf2,
(!global_version_no_value) ? global_version : NULL,
0,
- global_standalone);
+ global_standalone,
+ NULL);
appendBinaryStringInfo(&buf2, buf.data, buf.len);
buf = buf2;
@@ -674,7 +676,8 @@ xmltotext(PG_FUNCTION_ARGS)
text *
-xmltotext_with_options(xmltype *data, XmlOptionType xmloption_arg, bool indent)
+xmltotext_with_options(xmltype *data, XmlOptionType xmloption_arg, bool indent,
+ XmlSerializeDeclarationOption xmldeclaration, const char *xmlserialize_version)
{
#ifdef USE_LIBXML
text *volatile result;
@@ -685,9 +688,12 @@ xmltotext_with_options(xmltype *data, XmlOptionType xmloption_arg, bool indent)
volatile xmlSaveCtxtPtr ctxt = NULL;
ErrorSaveContext escontext = {T_ErrorSaveContext};
PgXmlErrorContext *volatile xmlerrcxt = NULL;
+ StringInfoData xmldecl;
#endif
- if (xmloption_arg != XMLOPTION_DOCUMENT && !indent)
+ if (xmloption_arg != XMLOPTION_DOCUMENT &&
+ xmldeclaration == XMLSERIALIZE_NO_XMLDECLARATION_OPTION &&
+ !indent && !xmlserialize_version)
{
/*
* We don't actually need to do anything, so just return the
@@ -718,8 +724,12 @@ xmltotext_with_options(xmltype *data, XmlOptionType xmloption_arg, bool indent)
errmsg("not an XML document")));
}
- /* If we weren't asked to indent, we're done. */
- if (!indent)
+ /*
+ * If we weren't asked to indent or to explicitly hide / show the
+ * XML declaration, we're done.
+ */
+ if (!indent && !xmlserialize_version &&
+ xmldeclaration == XMLSERIALIZE_NO_XMLDECLARATION_OPTION)
{
xmlFreeDoc(doc);
return (text *) data;
@@ -748,17 +758,15 @@ xmltotext_with_options(xmltype *data, XmlOptionType xmloption_arg, bool indent)
parse_xml_decl(xml_text2xmlChar(data), &decl_len, NULL, NULL, NULL);
/*
- * Emit declaration only if the input had one. Note: some versions of
- * xmlSaveToBuffer leak memory if a non-null encoding argument is
- * passed, so don't do that. We don't want any encoding conversion
- * anyway.
+ * Indent the buffer content if the flag INDENT was used.
+ * Note: some versions of xmlSaveToBuffer leak memory if a
+ * non-null encoding argument is passed, so don't do that.
+ * We don't want any encoding conversion anyway. The flag
+ * XML_SAVE_NO_DECL is used here by default, as we manually
+ * add the XML declaration later on with xmlBufferAddHead(),
+ * if applicable.
*/
- if (decl_len == 0)
- ctxt = xmlSaveToBuffer(buf, NULL,
- XML_SAVE_NO_DECL | XML_SAVE_FORMAT);
- else
- ctxt = xmlSaveToBuffer(buf, NULL,
- XML_SAVE_FORMAT);
+ ctxt = xmlSaveToBuffer(buf, NULL, XML_SAVE_NO_DECL | (indent ? XML_SAVE_FORMAT : 0));
if (ctxt == NULL || xmlerrcxt->err_occurred)
xml_ereport(xmlerrcxt, ERROR, ERRCODE_OUT_OF_MEMORY,
@@ -781,7 +789,7 @@ xmltotext_with_options(xmltype *data, XmlOptionType xmloption_arg, bool indent)
*/
xmlNodePtr root;
xmlNodePtr oldroot;
- xmlNodePtr newline;
+ xmlNodePtr newline = NULL;
root = xmlNewNode(NULL, (const xmlChar *) "content-root");
if (root == NULL || xmlerrcxt->err_occurred)
@@ -808,19 +816,24 @@ xmltotext_with_options(xmltype *data, XmlOptionType xmloption_arg, bool indent)
* freeing of this node manually, and pass NULL here to make sure
* there's not a dangling link.
*/
- newline = xmlNewDocText(NULL, (const xmlChar *) "\n");
- if (newline == NULL || xmlerrcxt->err_occurred)
- xml_ereport(xmlerrcxt, ERROR, ERRCODE_OUT_OF_MEMORY,
- "could not allocate xml node");
+ if (indent)
+ {
+ newline = xmlNewDocText(NULL, (const xmlChar *)"\n");
+
+ if (newline == NULL || xmlerrcxt->err_occurred)
+ xml_ereport(xmlerrcxt, ERROR, ERRCODE_OUT_OF_MEMORY,
+ "could not allocate xml node");
+ }
for (xmlNodePtr node = root->children; node; node = node->next)
{
/* insert newlines between nodes */
- if (node->type != XML_TEXT_NODE && node->prev != NULL)
+ if (node->type != XML_TEXT_NODE && node->prev != NULL && newline != NULL)
{
if (xmlSaveTree(ctxt, newline) == -1 || xmlerrcxt->err_occurred)
{
- xmlFreeNode(newline);
+ if(newline != NULL)
+ xmlFreeNode(newline);
xml_ereport(xmlerrcxt, ERROR, ERRCODE_OUT_OF_MEMORY,
"could not save newline to xmlBuffer");
}
@@ -834,7 +847,49 @@ xmltotext_with_options(xmltype *data, XmlOptionType xmloption_arg, bool indent)
}
}
- xmlFreeNode(newline);
+ if(newline != NULL)
+ xmlFreeNode(newline);
+ }
+
+ /*
+ * Emit declaration if the input had one or if it was explicitly
+ * requested via INCLUDING XMLDECLARATION (X078, SQL/XML:2023).
+ */
+ if (xmldeclaration == XMLSERIALIZE_INCLUDING_XMLDECLARATION ||
+ (decl_len != 0 && xmldeclaration != XMLSERIALIZE_EXCLUDING_XMLDECLARATION))
+ {
+ initStringInfo(&xmldecl);
+
+ /*
+ * No need to check the return value of print_xml_decl
+ * because we are forcing the XML declaration to be included
+ * by setting 'force_xmldeclaration' to true.
+ * Therefore, print_xml_decl will always succeed and produce output.
+ */
+ print_xml_decl(
+ &xmldecl,
+ /*
+ * Use version from VERSION option (X076, SQL/XML:2023)
+ * if specified; otherwise use the document's version.
+ */
+ xmlserialize_version != NULL ? (const xmlChar *)xmlserialize_version : doc->version,
+ pg_char_to_encoding((const char *)doc->encoding),
+ doc->standalone,
+ true);
+ /*
+ * We add a trailing newline if the flag INDENT was used,
+ * otherwise XML declaration and root element will be
+ * serialized in the same line.
+ */
+ if (indent)
+ appendStringInfoString(&xmldecl, "\n");
+
+ if (xmlBufferAddHead(buf, (const xmlChar *)xmldecl.data, xmldecl.len) < 0 ||
+ xmlerrcxt->err_occurred)
+ xml_ereport(xmlerrcxt, ERROR, ERRCODE_INTERNAL_ERROR,
+ "could not add XML declaration");
+
+ pfree(xmldecl.data);
}
if (xmlSaveClose(ctxt) == -1 || xmlerrcxt->err_occurred)
@@ -869,6 +924,8 @@ xmltotext_with_options(xmltype *data, XmlOptionType xmloption_arg, bool indent)
xmlBufferFree(buf);
xmlFreeDoc(doc);
+ if (xmldecl.data)
+ pfree(xmldecl.data);
if (xmlerrcxt)
pg_xml_done(xmlerrcxt, true);
@@ -881,6 +938,18 @@ xmltotext_with_options(xmltype *data, XmlOptionType xmloption_arg, bool indent)
pg_xml_done(xmlerrcxt, false);
+ /*
+ * If the flag VERSION was used with a DOCUMENT xml value we
+ * make sure that the passed version is valid. We let xml_parse()
+ * and xmlNewDoc() decide if an unexpected version deserves an
+ * error or just a warning. CONTENT xml values won't be validated.
+ */
+ if (xmloption_arg == XMLOPTION_DOCUMENT && xmlserialize_version &&
+ !xml_is_document((xmltype *) result))
+ ereport(ERROR,
+ (errcode(ERRCODE_NOT_AN_XML_DOCUMENT),
+ errmsg("invalid XML declaration: VERSION '%s'", xmlserialize_version)));
+
return result;
#else
NO_XML_SUPPORT();
@@ -1134,7 +1203,7 @@ xmlroot(xmltype *data, text *version, int standalone)
}
initStringInfo(&buf);
- print_xml_decl(&buf, orig_version, 0, orig_standalone);
+ print_xml_decl(&buf, orig_version, 0, orig_standalone, false);
appendStringInfoString(&buf, str + len);
return stringinfo_to_xmltype(&buf);
@@ -1639,14 +1708,20 @@ parse_xml_decl(const xmlChar *str, size_t *lenp,
* declaration, we must specify a version (XML requires this).
* Otherwise we only make a declaration if the version is not "1.0",
* which is the default version specified in SQL:2003.
+ *
+ * The parameter 'force_xmldeclaration' forces the function to print
+ * the XML declaration, indenpendently of version and encoding values.
+ * This is useful for XMLSerialize calls with the flag INCLUDING
+ * XMLDECLARATION.
*/
static bool
print_xml_decl(StringInfo buf, const xmlChar *version,
- pg_enc encoding, int standalone)
+ pg_enc encoding, int standalone,
+ bool force_xmldeclaration)
{
if ((version && strcmp((const char *) version, PG_XML_DEFAULT_VERSION) != 0)
|| (encoding && encoding != PG_UTF8)
- || standalone != -1)
+ || standalone != -1 || force_xmldeclaration)
{
appendStringInfoString(buf, "73' AS text INDENT);
- xmlserialize
-----------------------------------------
- +
- +
- +
- 73 +
- +
+ xmlserialize
+---------------------------------------
+ +
+ +
+ +
+ 73 +
+ +
(1 row)
SELECT xmlserialize(CONTENT '73' AS text INDENT);
- xmlserialize
--------------------
- +
- +
- 73+
- +
+ xmlserialize
+---------------------------------------
+ +
+ +
+ +
+ 73 +
+ +
(1 row)
@@ -676,6 +677,407 @@ SELECT xmlserialize(CONTENT 'text node ' AS text IN
(1 row)
+-- 'including xmldeclaration' and 'excluding xmldeclaration'(DOCUMENT)
+SELECT xmlserialize(DOCUMENT '42'::xml AS text INCLUDING XMLDECLARATION);
+ xmlserialize
+---------------------------------------------------------------
+ 42
+(1 row)
+
+SELECT xmlserialize(DOCUMENT '42'::xml AS text EXCLUDING XMLDECLARATION);
+ xmlserialize
+--------------------------
+ 42
+(1 row)
+
+SELECT xmlserialize(DOCUMENT '42'::xml AS text INCLUDING XMLDECLARATION);
+ xmlserialize
+---------------------------------------------------------------
+ 42
+(1 row)
+
+SELECT xmlserialize(DOCUMENT '42'::xml AS text EXCLUDING XMLDECLARATION);
+ xmlserialize
+--------------------------
+ 42
+(1 row)
+
+SELECT xmlserialize(DOCUMENT '42'::xml AS text INCLUDING XMLDECLARATION);
+ xmlserialize
+-------------------------------------------------------------------------------
+ 42
+(1 row)
+
+SELECT xmlserialize(DOCUMENT '42'::xml AS text INCLUDING XMLDECLARATION);
+ xmlserialize
+--------------------------------------------------------------------------------
+ 42
+(1 row)
+
+-- 'including xmldeclaration' and 'excluding xmldeclaration'(CONTENT)
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text INCLUDING XMLDECLARATION);
+ xmlserialize
+------------------------------------------------------------------
+ txt42
+(1 row)
+
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text EXCLUDING XMLDECLARATION);
+ xmlserialize
+-----------------------------
+ txt42
+(1 row)
+
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text INCLUDING XMLDECLARATION);
+ xmlserialize
+------------------------------------------------------------------
+ txt42
+(1 row)
+
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text EXCLUDING XMLDECLARATION);
+ xmlserialize
+-----------------------------
+ txt42
+(1 row)
+
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text INCLUDING XMLDECLARATION);
+ xmlserialize
+----------------------------------------------------------------------------------
+ txt42
+(1 row)
+
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text INCLUDING XMLDECLARATION);
+ xmlserialize
+-----------------------------------------------------------------------------------
+ txt42
+(1 row)
+
+-- 'indent' + 'including xmldeclaration' and 'excluding xmldeclaration' (DOCUMENT)
+SELECT xmlserialize(DOCUMENT '42'::xml AS text INCLUDING XMLDECLARATION INDENT);
+ xmlserialize
+---------------------------------------
+ +
+ +
+ 42 +
+
+(1 row)
+
+SELECT xmlserialize(DOCUMENT '42'::xml AS text EXCLUDING XMLDECLARATION INDENT);
+ xmlserialize
+-----------------
+ +
+ 42+
+
+(1 row)
+
+SELECT xmlserialize(DOCUMENT '42'::xml AS text INCLUDING XMLDECLARATION INDENT);
+ xmlserialize
+---------------------------------------
+ +
+ +
+ 42 +
+
+(1 row)
+
+SELECT xmlserialize(DOCUMENT '42'::xml AS text EXCLUDING XMLDECLARATION INDENT);
+ xmlserialize
+-----------------
+ +
+ 42+
+
+(1 row)
+
+SELECT xmlserialize(DOCUMENT '42'::xml AS text INCLUDING XMLDECLARATION INDENT);
+ xmlserialize
+-------------------------------------------------------
+ +
+ +
+ 42 +
+
+(1 row)
+
+SELECT xmlserialize(DOCUMENT '42'::xml AS text INCLUDING XMLDECLARATION INDENT);
+ xmlserialize
+--------------------------------------------------------
+ +
+ +
+ 42 +
+
+(1 row)
+
+-- 'indent' + 'including xmldeclaration' and 'excluding xmldeclaration'(CONTENT)
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text INCLUDING XMLDECLARATION INDENT);
+ xmlserialize
+---------------------------------------
+ +
+ txt +
+ +
+ 42 +
+
+(1 row)
+
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text EXCLUDING XMLDECLARATION INDENT);
+ xmlserialize
+-----------------
+ txt +
+ +
+ 42+
+
+(1 row)
+
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text INCLUDING XMLDECLARATION INDENT);
+ xmlserialize
+---------------------------------------
+ +
+ txt +
+ +
+ 42 +
+
+(1 row)
+
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text EXCLUDING XMLDECLARATION INDENT);
+ xmlserialize
+-----------------
+ txt +
+ +
+ 42+
+
+(1 row)
+
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text INCLUDING XMLDECLARATION INDENT);
+ xmlserialize
+-------------------------------------------------------
+ +
+ txt +
+ +
+ 42 +
+
+(1 row)
+
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text INCLUDING XMLDECLARATION INDENT);
+ xmlserialize
+--------------------------------------------------------
+ +
+ txt +
+ +
+ 42 +
+
+(1 row)
+
+-- 'version' + 'including xmldeclaration' and 'excluding xmldeclaration'(DOCUMENT)
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.0');
+ xmlserialize
+--------------------------
+ 42
+(1 row)
+
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.0' INCLUDING XMLDECLARATION);
+ xmlserialize
+---------------------------------------------------------------
+ 42
+(1 row)
+
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.0');
+ xmlserialize
+-------------------------------------------------------------------------------
+ 42
+(1 row)
+
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.0' INCLUDING XMLDECLARATION);
+ xmlserialize
+--------------------------------------------------------------------------------
+ 42
+(1 row)
+
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.1' EXCLUDING XMLDECLARATION);
+ xmlserialize
+--------------------------
+ 42
+(1 row)
+
+-- 'version' + 'including xmldeclaration' and 'excluding xmldeclaration'(CONTENT)
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION '1.1');
+ xmlserialize
+-----------------------------
+ txt42
+(1 row)
+
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION '1.1' INCLUDING XMLDECLARATION);
+ xmlserialize
+------------------------------------------------------------------
+ txt42
+(1 row)
+
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION '1.1');
+ xmlserialize
+-----------------------------------------------------------------------------------
+ txt42
+(1 row)
+
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION '1.1' INCLUDING XMLDECLARATION);
+ xmlserialize
+----------------------------------------------------------------------------------
+ txt42
+(1 row)
+
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION '1.1' EXCLUDING XMLDECLARATION);
+ xmlserialize
+-----------------------------
+ txt42
+(1 row)
+
+-- 'version' + 'indent' (DOCUMENT)
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.0' INDENT);
+ xmlserialize
+-----------------
+ +
+ 42+
+
+(1 row)
+
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.0' INDENT);
+ xmlserialize
+-------------------------------------------------------
+ +
+ +
+ 42 +
+
+(1 row)
+
+-- 'indent' + 'version' (CONTENT)
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION '1.1' INDENT);
+ xmlserialize
+-----------------
+ txt +
+ +
+ 42+
+
+(1 row)
+
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION '1.1' INDENT);
+ xmlserialize
+--------------------------------------------------------
+ +
+ txt +
+ +
+ 42 +
+
+(1 row)
+
+-- 'indent' + 'version' + 'including xmldeclaration' and 'excluding xmldeclaration'(DOCUMENT)
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.0' INCLUDING XMLDECLARATION INDENT);
+ xmlserialize
+---------------------------------------
+ +
+ +
+ 42 +
+
+(1 row)
+
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.0' INCLUDING XMLDECLARATION INDENT);
+ xmlserialize
+--------------------------------------------------------
+ +
+ +
+ 42 +
+
+(1 row)
+
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.0' EXCLUDING XMLDECLARATION INDENT);
+ xmlserialize
+-----------------
+ +
+ 42+
+
+(1 row)
+
+-- 'indent' + 'version' + 'including xmldeclaration' and 'excluding xmldeclaration'(CONTENT)
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION '1.1' INCLUDING XMLDECLARATION INDENT);
+ xmlserialize
+---------------------------------------
+ +
+ txt +
+ +
+ 42 +
+
+(1 row)
+
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION '1.1' INCLUDING XMLDECLARATION INDENT);
+ xmlserialize
+--------------------------------------------------------
+ +
+ txt +
+ +
+ 42 +
+
+(1 row)
+
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION '1.1' EXCLUDING XMLDECLARATION INDENT);
+ xmlserialize
+-----------------
+ txt +
+ +
+ 42+
+
+(1 row)
+
+--'version' with null value (DOCUMENT)
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION NULL);
+ xmlserialize
+--------------------------
+ 42
+(1 row)
+
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION NULL EXCLUDING XMLDECLARATION);
+ xmlserialize
+--------------------------
+ 42
+(1 row)
+
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION NULL INCLUDING XMLDECLARATION);
+ xmlserialize
+---------------------------------------------------------------
+ 42
+(1 row)
+
+--'version' with null value (CONTENT)
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION NULL);
+ xmlserialize
+-----------------------------
+ txt42
+(1 row)
+
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION NULL EXCLUDING XMLDECLARATION);
+ xmlserialize
+-----------------------------
+ txt42
+(1 row)
+
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION NULL INCLUDING XMLDECLARATION);
+ xmlserialize
+------------------------------------------------------------------
+ txt42
+(1 row)
+
+-- 'version' + 'including xmldeclaration' warning and error messages
+\set VERBOSITY terse
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.1' INCLUDING XMLDECLARATION);
+WARNING: line 1: Unsupported version '1.1'
+42
+ ^
+ xmlserialize
+---------------------------------------------------------------
+ 42
+(1 row)
+
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '2.0' INCLUDING XMLDECLARATION);
+ERROR: invalid XML declaration: VERSION '2.0'
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '' INCLUDING XMLDECLARATION);
+ERROR: invalid XML declaration: VERSION ''
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION ' ' INCLUDING XMLDECLARATION);
+ERROR: invalid XML declaration: VERSION ' '
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION 'foo' INCLUDING XMLDECLARATION);
+ERROR: invalid XML declaration: VERSION 'foo'
+\set VERBOSITY default
SELECT xml 'bar' IS DOCUMENT;
?column?
----------
@@ -824,23 +1226,41 @@ CREATE VIEW xmlview8 AS SELECT xmlserialize(content 'good' as char(10));
CREATE VIEW xmlview9 AS SELECT xmlserialize(content 'good' as text);
CREATE VIEW xmlview10 AS SELECT xmlserialize(document '42' AS text indent);
CREATE VIEW xmlview11 AS SELECT xmlserialize(document '42' AS character varying no indent);
+CREATE VIEW xmlview12 AS SELECT xmlserialize(document '42' AS text including xmldeclaration);
+CREATE VIEW xmlview13 AS SELECT xmlserialize(document '42' AS text excluding xmldeclaration);
+CREATE VIEW xmlview14 AS SELECT xmlserialize(document '42' AS text including xmldeclaration indent);
+CREATE VIEW xmlview15 AS SELECT xmlserialize(document '42' AS text excluding xmldeclaration indent);
+CREATE VIEW xmlview16 AS SELECT xmlserialize(document '42' AS text including xmldeclaration no indent);
+CREATE VIEW xmlview17 AS SELECT xmlserialize(document '42' AS text excluding xmldeclaration no indent);
+CREATE VIEW xmlview18 AS SELECT xmlserialize(document '42' AS text version '1.0' including xmldeclaration indent);
+CREATE VIEW xmlview19 AS SELECT xmlserialize(document '42' AS text version '1.0' including xmldeclaration no indent);
+CREATE VIEW xmlview20 AS SELECT xmlserialize(document '42' AS text version '1.0');
SELECT table_name, view_definition FROM information_schema.views
WHERE table_name LIKE 'xmlview%' ORDER BY 1;
- table_name | view_definition
-------------+---------------------------------------------------------------------------------------------------------------------------------------
+ table_name | view_definition
+------------+--------------------------------------------------------------------------------------------------------------------------------------------
xmlview1 | SELECT xmlcomment('test'::text) AS xmlcomment;
xmlview10 | SELECT XMLSERIALIZE(DOCUMENT '42'::xml AS text INDENT) AS "xmlserialize";
xmlview11 | SELECT (XMLSERIALIZE(DOCUMENT '42'::xml AS character varying NO INDENT))::character varying AS "xmlserialize";
+ xmlview12 | SELECT XMLSERIALIZE(DOCUMENT '42'::xml AS text INCLUDING XMLDECLARATION NO INDENT) AS "xmlserialize";
+ xmlview13 | SELECT XMLSERIALIZE(DOCUMENT '42'::xml AS text EXCLUDING XMLDECLARATION NO INDENT) AS "xmlserialize";
+ xmlview14 | SELECT XMLSERIALIZE(DOCUMENT '42'::xml AS text INCLUDING XMLDECLARATION INDENT) AS "xmlserialize";
+ xmlview15 | SELECT XMLSERIALIZE(DOCUMENT '42'::xml AS text EXCLUDING XMLDECLARATION INDENT) AS "xmlserialize";
+ xmlview16 | SELECT XMLSERIALIZE(DOCUMENT '42'::xml AS text INCLUDING XMLDECLARATION NO INDENT) AS "xmlserialize";
+ xmlview17 | SELECT XMLSERIALIZE(DOCUMENT '42'::xml AS text EXCLUDING XMLDECLARATION NO INDENT) AS "xmlserialize";
+ xmlview18 | SELECT XMLSERIALIZE(DOCUMENT '42'::xml AS text VERSION '1.0' INCLUDING XMLDECLARATION INDENT) AS "xmlserialize";
+ xmlview19 | SELECT XMLSERIALIZE(DOCUMENT '42'::xml AS text VERSION '1.0' INCLUDING XMLDECLARATION NO INDENT) AS "xmlserialize";
xmlview2 | SELECT XMLCONCAT('hello'::xml, 'you'::xml) AS "xmlconcat";
+ xmlview20 | SELECT XMLSERIALIZE(DOCUMENT '42'::xml AS text VERSION '1.0' NO INDENT) AS "xmlserialize";
xmlview3 | SELECT XMLELEMENT(NAME element, XMLATTRIBUTES(1 AS ":one:", 'deuce' AS two), 'content&') AS "xmlelement";
- xmlview4 | SELECT XMLELEMENT(NAME employee, XMLFOREST(name AS name, age AS age, salary AS pay)) AS "xmlelement" +
+ xmlview4 | SELECT XMLELEMENT(NAME employee, XMLFOREST(name AS name, age AS age, salary AS pay)) AS "xmlelement" +
| FROM emp;
xmlview5 | SELECT XMLPARSE(CONTENT 'x'::text STRIP WHITESPACE) AS "xmlparse";
xmlview6 | SELECT XMLPI(NAME foo, 'bar'::text) AS "xmlpi";
xmlview7 | SELECT XMLROOT(''::xml, VERSION NO VALUE, STANDALONE YES) AS "xmlroot";
xmlview8 | SELECT (XMLSERIALIZE(CONTENT 'good'::xml AS character(10) NO INDENT))::character(10) AS "xmlserialize";
xmlview9 | SELECT XMLSERIALIZE(CONTENT 'good'::xml AS text NO INDENT) AS "xmlserialize";
-(11 rows)
+(20 rows)
-- Text XPath expressions evaluation
SELECT xpath('/value', data) FROM xmltest;
diff --git a/src/test/regress/expected/xml_1.out b/src/test/regress/expected/xml_1.out
index 73c411118a39..236a07a1ba2b 100644
--- a/src/test/regress/expected/xml_1.out
+++ b/src/test/regress/expected/xml_1.out
@@ -454,6 +454,281 @@ ERROR: unsupported XML feature
LINE 1: SELECT xmlserialize(CONTENT 'text node ...
^
DETAIL: This functionality requires the server to be built with libxml support.
+-- 'including xmldeclaration' and 'excluding xmldeclaration'(DOCUMENT)
+SELECT xmlserialize(DOCUMENT '42'::xml AS text INCLUDING XMLDECLARATION);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(DOCUMENT '42'::xml...
+ ^
+DETAIL: This functionality requires the server to be built with libxml support.
+SELECT xmlserialize(DOCUMENT '42'::xml AS text EXCLUDING XMLDECLARATION);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(DOCUMENT '42'::xml...
+ ^
+DETAIL: This functionality requires the server to be built with libxml support.
+SELECT xmlserialize(DOCUMENT '42'::xml AS text INCLUDING XMLDECLARATION);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(DOCUMENT '42'::xml AS text EXCLUDING XMLDECLARATION);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(DOCUMENT '42'::xml AS text INCLUDING XMLDECLARATION);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(DOCUMENT '42'::xml AS text INCLUDING XMLDECLARATION);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(DOCUMENT '42'::xml AS text INCLUDING XMLDECLARATION);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(CONTENT 'txt42'::x...
+ ^
+DETAIL: This functionality requires the server to be built with libxml support.
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text EXCLUDING XMLDECLARATION);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(CONTENT 'txt42'::x...
+ ^
+DETAIL: This functionality requires the server to be built with libxml support.
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text INCLUDING XMLDECLARATION);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(CONTENT 'txt42'::xml AS text EXCLUDING XMLDECLARATION);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(CONTENT 'txt42'::xml AS text INCLUDING XMLDECLARATION);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(CONTENT 'txt42'::xml AS text INCLUDING XMLDECLARATION);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(CONTENT '42'::xml AS text INCLUDING XMLDECLARATION INDENT);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(DOCUMENT '42'::xml...
+ ^
+DETAIL: This functionality requires the server to be built with libxml support.
+SELECT xmlserialize(DOCUMENT '42'::xml AS text EXCLUDING XMLDECLARATION INDENT);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(DOCUMENT '42'::xml...
+ ^
+DETAIL: This functionality requires the server to be built with libxml support.
+SELECT xmlserialize(DOCUMENT '42'::xml AS text INCLUDING XMLDECLARATION INDENT);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(DOCUMENT '42'::xml AS text EXCLUDING XMLDECLARATION INDENT);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(DOCUMENT '42'::xml AS text INCLUDING XMLDECLARATION INDENT);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(DOCUMENT '42'::xml AS text INCLUDING XMLDECLARATION INDENT);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(DOCUMENT '42'::xml AS text INCLUDING XMLDECLARATION INDENT);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(CONTENT 'txt42'::x...
+ ^
+DETAIL: This functionality requires the server to be built with libxml support.
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text EXCLUDING XMLDECLARATION INDENT);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(CONTENT 'txt42'::x...
+ ^
+DETAIL: This functionality requires the server to be built with libxml support.
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text INCLUDING XMLDECLARATION INDENT);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(CONTENT 'txt42'::xml AS text EXCLUDING XMLDECLARATION INDENT);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(CONTENT 'txt42'::xml AS text INCLUDING XMLDECLARATION INDENT);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(CONTENT 'txt42'::xml AS text INCLUDING XMLDECLARATION INDENT);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(CONTENT '42'::xml AS text VERSION '1.0');
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(DOCUMENT '42'::xml...
+ ^
+DETAIL: This functionality requires the server to be built with libxml support.
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.0' INCLUDING XMLDECLARATION);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(DOCUMENT '42'::xml...
+ ^
+DETAIL: This functionality requires the server to be built with libxml support.
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.0');
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.0' INCLUDING XMLDECLARATION);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.1' EXCLUDING XMLDECLARATION);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.1');
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(CONTENT 'txt42'::x...
+ ^
+DETAIL: This functionality requires the server to be built with libxml support.
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION '1.1' INCLUDING XMLDECLARATION);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(CONTENT 'txt42'::x...
+ ^
+DETAIL: This functionality requires the server to be built with libxml support.
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION '1.1');
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION '1.1' INCLUDING XMLDECLARATION);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION '1.1' EXCLUDING XMLDECLARATION);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(CONTENT '42'::xml AS text VERSION '1.0' INDENT);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(DOCUMENT '42'::xml...
+ ^
+DETAIL: This functionality requires the server to be built with libxml support.
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.0' INDENT);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.1' INDENT);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(CONTENT 'txt42'::x...
+ ^
+DETAIL: This functionality requires the server to be built with libxml support.
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION '1.1' INDENT);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(CONTENT '42'::xml AS text VERSION '1.0' INCLUDING XMLDECLARATION INDENT);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(DOCUMENT '42'::xml...
+ ^
+DETAIL: This functionality requires the server to be built with libxml support.
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.0' INCLUDING XMLDECLARATION INDENT);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.0' EXCLUDING XMLDECLARATION INDENT);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.1' INCLUDING XMLDECLARATION INDENT);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(CONTENT 'txt42'::x...
+ ^
+DETAIL: This functionality requires the server to be built with libxml support.
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION '1.1' INCLUDING XMLDECLARATION INDENT);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION '1.1' EXCLUDING XMLDECLARATION INDENT);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(CONTENT '42'::xml AS text VERSION NULL);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(DOCUMENT '42'::xml...
+ ^
+DETAIL: This functionality requires the server to be built with libxml support.
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION NULL EXCLUDING XMLDECLARATION);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(DOCUMENT '42'::xml...
+ ^
+DETAIL: This functionality requires the server to be built with libxml support.
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION NULL INCLUDING XMLDECLARATION);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(DOCUMENT '42'::xml...
+ ^
+DETAIL: This functionality requires the server to be built with libxml support.
+--'version' with null value (CONTENT)
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION NULL);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(CONTENT 'txt42'::x...
+ ^
+DETAIL: This functionality requires the server to be built with libxml support.
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION NULL EXCLUDING XMLDECLARATION);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(CONTENT 'txt42'::x...
+ ^
+DETAIL: This functionality requires the server to be built with libxml support.
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION NULL INCLUDING XMLDECLARATION);
+ERROR: unsupported XML feature
+LINE 1: SELECT xmlserialize(CONTENT 'txt42'::x...
+ ^
+DETAIL: This functionality requires the server to be built with libxml support.
+-- 'version' + 'including xmldeclaration' warning and error messages
+\set VERBOSITY terse
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.1' INCLUDING XMLDECLARATION);
+ERROR: unsupported XML feature at character 30
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '2.0' INCLUDING XMLDECLARATION);
+ERROR: unsupported XML feature at character 30
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '' INCLUDING XMLDECLARATION);
+ERROR: unsupported XML feature at character 30
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION ' ' INCLUDING XMLDECLARATION);
+ERROR: unsupported XML feature at character 30
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION 'foo' INCLUDING XMLDECLARATION);
+ERROR: unsupported XML feature at character 30
+\set VERBOSITY default
SELECT xml 'bar' IS DOCUMENT;
ERROR: unsupported XML feature
LINE 1: SELECT xml 'bar' IS DOCUMENT;
@@ -593,6 +868,51 @@ ERROR: unsupported XML feature
LINE 1: ...TE VIEW xmlview11 AS SELECT xmlserialize(document '42' AS text including xmldeclaration);
+ERROR: unsupported XML feature
+LINE 1: ...TE VIEW xmlview12 AS SELECT xmlserialize(document '42' AS text excluding xmldeclaration);
+ERROR: unsupported XML feature
+LINE 1: ...TE VIEW xmlview13 AS SELECT xmlserialize(document '42' AS text including xmldeclaration indent);
+ERROR: unsupported XML feature
+LINE 1: ...TE VIEW xmlview14 AS SELECT xmlserialize(document '42' AS text excluding xmldeclaration indent);
+ERROR: unsupported XML feature
+LINE 1: ...TE VIEW xmlview15 AS SELECT xmlserialize(document '42' AS text including xmldeclaration no indent);
+ERROR: unsupported XML feature
+LINE 1: ...TE VIEW xmlview16 AS SELECT xmlserialize(document '42' AS text excluding xmldeclaration no indent);
+ERROR: unsupported XML feature
+LINE 1: ...TE VIEW xmlview17 AS SELECT xmlserialize(document '42' AS text version '1.0' including xmldeclaration indent);
+ERROR: unsupported XML feature
+LINE 1: ...TE VIEW xmlview18 AS SELECT xmlserialize(document '42' AS text version '1.0' including xmldeclaration no indent);
+ERROR: unsupported XML feature
+LINE 1: ...TE VIEW xmlview19 AS SELECT xmlserialize(document '42' AS text version '1.0');
+ERROR: unsupported XML feature
+LINE 1: ...TE VIEW xmlview20 AS SELECT xmlserialize(document ' ' AS text IN
(1 row)
+-- 'including xmldeclaration' and 'excluding xmldeclaration'(DOCUMENT)
+SELECT xmlserialize(DOCUMENT '42'::xml AS text INCLUDING XMLDECLARATION);
+ xmlserialize
+---------------------------------------------------------------
+ 42
+(1 row)
+
+SELECT xmlserialize(DOCUMENT '42'::xml AS text EXCLUDING XMLDECLARATION);
+ xmlserialize
+--------------------------
+ 42
+(1 row)
+
+SELECT xmlserialize(DOCUMENT '42'::xml AS text INCLUDING XMLDECLARATION);
+ xmlserialize
+---------------------------------------------------------------
+ 42
+(1 row)
+
+SELECT xmlserialize(DOCUMENT '42'::xml AS text EXCLUDING XMLDECLARATION);
+ xmlserialize
+--------------------------
+ 42
+(1 row)
+
+SELECT xmlserialize(DOCUMENT '42'::xml AS text INCLUDING XMLDECLARATION);
+ xmlserialize
+-------------------------------------------------------------------------------
+ 42
+(1 row)
+
+SELECT xmlserialize(DOCUMENT '42'::xml AS text INCLUDING XMLDECLARATION);
+ xmlserialize
+--------------------------------------------------------------------------------
+ 42
+(1 row)
+
+-- 'including xmldeclaration' and 'excluding xmldeclaration'(CONTENT)
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text INCLUDING XMLDECLARATION);
+ xmlserialize
+------------------------------------------------------------------
+ txt42
+(1 row)
+
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text EXCLUDING XMLDECLARATION);
+ xmlserialize
+-----------------------------
+ txt42
+(1 row)
+
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text INCLUDING XMLDECLARATION);
+ xmlserialize
+------------------------------------------------------------------
+ txt42
+(1 row)
+
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text EXCLUDING XMLDECLARATION);
+ xmlserialize
+-----------------------------
+ txt42
+(1 row)
+
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text INCLUDING XMLDECLARATION);
+ xmlserialize
+----------------------------------------------------------------------------------
+ txt42
+(1 row)
+
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text INCLUDING XMLDECLARATION);
+ xmlserialize
+-----------------------------------------------------------------------------------
+ txt42
+(1 row)
+
+-- 'indent' + 'including xmldeclaration' and 'excluding xmldeclaration' (DOCUMENT)
+SELECT xmlserialize(DOCUMENT '42'::xml AS text INCLUDING XMLDECLARATION INDENT);
+ xmlserialize
+---------------------------------------
+ +
+ +
+ 42 +
+
+(1 row)
+
+SELECT xmlserialize(DOCUMENT '42'::xml AS text EXCLUDING XMLDECLARATION INDENT);
+ xmlserialize
+-----------------
+ +
+ 42+
+
+(1 row)
+
+SELECT xmlserialize(DOCUMENT '42'::xml AS text INCLUDING XMLDECLARATION INDENT);
+ xmlserialize
+---------------------------------------
+ +
+ +
+ 42 +
+
+(1 row)
+
+SELECT xmlserialize(DOCUMENT '42'::xml AS text EXCLUDING XMLDECLARATION INDENT);
+ xmlserialize
+-----------------
+ +
+ 42+
+
+(1 row)
+
+SELECT xmlserialize(DOCUMENT '42'::xml AS text INCLUDING XMLDECLARATION INDENT);
+ xmlserialize
+-------------------------------------------------------
+ +
+ +
+ 42 +
+
+(1 row)
+
+SELECT xmlserialize(DOCUMENT '42'::xml AS text INCLUDING XMLDECLARATION INDENT);
+ xmlserialize
+--------------------------------------------------------
+ +
+ +
+ 42 +
+
+(1 row)
+
+-- 'indent' + 'including xmldeclaration' and 'excluding xmldeclaration'(CONTENT)
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text INCLUDING XMLDECLARATION INDENT);
+ xmlserialize
+---------------------------------------
+ +
+ txt +
+ +
+ 42 +
+
+(1 row)
+
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text EXCLUDING XMLDECLARATION INDENT);
+ xmlserialize
+-----------------
+ txt +
+ +
+ 42+
+
+(1 row)
+
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text INCLUDING XMLDECLARATION INDENT);
+ xmlserialize
+---------------------------------------
+ +
+ txt +
+ +
+ 42 +
+
+(1 row)
+
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text EXCLUDING XMLDECLARATION INDENT);
+ xmlserialize
+-----------------
+ txt +
+ +
+ 42+
+
+(1 row)
+
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text INCLUDING XMLDECLARATION INDENT);
+ xmlserialize
+-------------------------------------------------------
+ +
+ txt +
+ +
+ 42 +
+
+(1 row)
+
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text INCLUDING XMLDECLARATION INDENT);
+ xmlserialize
+--------------------------------------------------------
+ +
+ txt +
+ +
+ 42 +
+
+(1 row)
+
+-- 'version' + 'including xmldeclaration' and 'excluding xmldeclaration'(DOCUMENT)
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.0');
+ xmlserialize
+--------------------------
+ 42
+(1 row)
+
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.0' INCLUDING XMLDECLARATION);
+ xmlserialize
+---------------------------------------------------------------
+ 42
+(1 row)
+
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.0');
+ xmlserialize
+-------------------------------------------------------------------------------
+ 42
+(1 row)
+
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.0' INCLUDING XMLDECLARATION);
+ xmlserialize
+--------------------------------------------------------------------------------
+ 42
+(1 row)
+
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.1' EXCLUDING XMLDECLARATION);
+ xmlserialize
+--------------------------
+ 42
+(1 row)
+
+-- 'version' + 'including xmldeclaration' and 'excluding xmldeclaration'(CONTENT)
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION '1.1');
+ xmlserialize
+-----------------------------
+ txt42
+(1 row)
+
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION '1.1' INCLUDING XMLDECLARATION);
+ xmlserialize
+------------------------------------------------------------------
+ txt42
+(1 row)
+
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION '1.1');
+ xmlserialize
+-----------------------------------------------------------------------------------
+ txt42
+(1 row)
+
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION '1.1' INCLUDING XMLDECLARATION);
+ xmlserialize
+----------------------------------------------------------------------------------
+ txt42
+(1 row)
+
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION '1.1' EXCLUDING XMLDECLARATION);
+ xmlserialize
+-----------------------------
+ txt42
+(1 row)
+
+-- 'version' + 'indent' (DOCUMENT)
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.0' INDENT);
+ xmlserialize
+-----------------
+ +
+ 42+
+
+(1 row)
+
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.0' INDENT);
+ xmlserialize
+-------------------------------------------------------
+ +
+ +
+ 42 +
+
+(1 row)
+
+-- 'indent' + 'version' (CONTENT)
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION '1.1' INDENT);
+ xmlserialize
+-----------------
+ txt +
+ +
+ 42+
+
+(1 row)
+
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION '1.1' INDENT);
+ xmlserialize
+--------------------------------------------------------
+ +
+ txt +
+ +
+ 42 +
+
+(1 row)
+
+-- 'indent' + 'version' + 'including xmldeclaration' and 'excluding xmldeclaration'(DOCUMENT)
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.0' INCLUDING XMLDECLARATION INDENT);
+ xmlserialize
+---------------------------------------
+ +
+ +
+ 42 +
+
+(1 row)
+
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.0' INCLUDING XMLDECLARATION INDENT);
+ xmlserialize
+--------------------------------------------------------
+ +
+ +
+ 42 +
+
+(1 row)
+
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.0' EXCLUDING XMLDECLARATION INDENT);
+ xmlserialize
+-----------------
+ +
+ 42+
+
+(1 row)
+
+-- 'indent' + 'version' + 'including xmldeclaration' and 'excluding xmldeclaration'(CONTENT)
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION '1.1' INCLUDING XMLDECLARATION INDENT);
+ xmlserialize
+---------------------------------------
+ +
+ txt +
+ +
+ 42 +
+
+(1 row)
+
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION '1.1' INCLUDING XMLDECLARATION INDENT);
+ xmlserialize
+--------------------------------------------------------
+ +
+ txt +
+ +
+ 42 +
+
+(1 row)
+
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION '1.1' EXCLUDING XMLDECLARATION INDENT);
+ xmlserialize
+-----------------
+ txt +
+ +
+ 42+
+
+(1 row)
+
+--'version' with null value (DOCUMENT)
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION NULL);
+ xmlserialize
+--------------------------
+ 42
+(1 row)
+
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION NULL EXCLUDING XMLDECLARATION);
+ xmlserialize
+--------------------------
+ 42
+(1 row)
+
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION NULL INCLUDING XMLDECLARATION);
+ xmlserialize
+---------------------------------------------------------------
+ 42
+(1 row)
+
+--'version' with null value (CONTENT)
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION NULL);
+ xmlserialize
+-----------------------------
+ txt42
+(1 row)
+
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION NULL EXCLUDING XMLDECLARATION);
+ xmlserialize
+-----------------------------
+ txt42
+(1 row)
+
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION NULL INCLUDING XMLDECLARATION);
+ xmlserialize
+------------------------------------------------------------------
+ txt42
+(1 row)
+
+-- 'version' + 'including xmldeclaration' warning and error messages
+\set VERBOSITY terse
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.1' INCLUDING XMLDECLARATION);
+WARNING: line 1: Unsupported version '1.1'
+42
+ ^
+ xmlserialize
+---------------------------------------------------------------
+ 42
+(1 row)
+
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '2.0' INCLUDING XMLDECLARATION);
+ERROR: invalid XML declaration: VERSION '2.0'
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '' INCLUDING XMLDECLARATION);
+ERROR: invalid XML declaration: VERSION ''
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION ' ' INCLUDING XMLDECLARATION);
+ERROR: invalid XML declaration: VERSION ' '
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION 'foo' INCLUDING XMLDECLARATION);
+ERROR: invalid XML declaration: VERSION 'foo'
+\set VERBOSITY default
SELECT xml 'bar' IS DOCUMENT;
?column?
----------
@@ -810,23 +1211,41 @@ CREATE VIEW xmlview8 AS SELECT xmlserialize(content 'good' as char(10));
CREATE VIEW xmlview9 AS SELECT xmlserialize(content 'good' as text);
CREATE VIEW xmlview10 AS SELECT xmlserialize(document '42' AS text indent);
CREATE VIEW xmlview11 AS SELECT xmlserialize(document '42' AS character varying no indent);
+CREATE VIEW xmlview12 AS SELECT xmlserialize(document '42' AS text including xmldeclaration);
+CREATE VIEW xmlview13 AS SELECT xmlserialize(document '42' AS text excluding xmldeclaration);
+CREATE VIEW xmlview14 AS SELECT xmlserialize(document '42' AS text including xmldeclaration indent);
+CREATE VIEW xmlview15 AS SELECT xmlserialize(document '42' AS text excluding xmldeclaration indent);
+CREATE VIEW xmlview16 AS SELECT xmlserialize(document '42' AS text including xmldeclaration no indent);
+CREATE VIEW xmlview17 AS SELECT xmlserialize(document '42' AS text excluding xmldeclaration no indent);
+CREATE VIEW xmlview18 AS SELECT xmlserialize(document '42' AS text version '1.0' including xmldeclaration indent);
+CREATE VIEW xmlview19 AS SELECT xmlserialize(document '42' AS text version '1.0' including xmldeclaration no indent);
+CREATE VIEW xmlview20 AS SELECT xmlserialize(document '42' AS text version '1.0');
SELECT table_name, view_definition FROM information_schema.views
WHERE table_name LIKE 'xmlview%' ORDER BY 1;
- table_name | view_definition
-------------+---------------------------------------------------------------------------------------------------------------------------------------
+ table_name | view_definition
+------------+--------------------------------------------------------------------------------------------------------------------------------------------
xmlview1 | SELECT xmlcomment('test'::text) AS xmlcomment;
xmlview10 | SELECT XMLSERIALIZE(DOCUMENT '42'::xml AS text INDENT) AS "xmlserialize";
xmlview11 | SELECT (XMLSERIALIZE(DOCUMENT '42'::xml AS character varying NO INDENT))::character varying AS "xmlserialize";
+ xmlview12 | SELECT XMLSERIALIZE(DOCUMENT '42'::xml AS text INCLUDING XMLDECLARATION NO INDENT) AS "xmlserialize";
+ xmlview13 | SELECT XMLSERIALIZE(DOCUMENT '42'::xml AS text EXCLUDING XMLDECLARATION NO INDENT) AS "xmlserialize";
+ xmlview14 | SELECT XMLSERIALIZE(DOCUMENT '42'::xml AS text INCLUDING XMLDECLARATION INDENT) AS "xmlserialize";
+ xmlview15 | SELECT XMLSERIALIZE(DOCUMENT '42'::xml AS text EXCLUDING XMLDECLARATION INDENT) AS "xmlserialize";
+ xmlview16 | SELECT XMLSERIALIZE(DOCUMENT '42'::xml AS text INCLUDING XMLDECLARATION NO INDENT) AS "xmlserialize";
+ xmlview17 | SELECT XMLSERIALIZE(DOCUMENT '42'::xml AS text EXCLUDING XMLDECLARATION NO INDENT) AS "xmlserialize";
+ xmlview18 | SELECT XMLSERIALIZE(DOCUMENT '42'::xml AS text VERSION '1.0' INCLUDING XMLDECLARATION INDENT) AS "xmlserialize";
+ xmlview19 | SELECT XMLSERIALIZE(DOCUMENT '42'::xml AS text VERSION '1.0' INCLUDING XMLDECLARATION NO INDENT) AS "xmlserialize";
xmlview2 | SELECT XMLCONCAT('hello'::xml, 'you'::xml) AS "xmlconcat";
+ xmlview20 | SELECT XMLSERIALIZE(DOCUMENT '42'::xml AS text VERSION '1.0' NO INDENT) AS "xmlserialize";
xmlview3 | SELECT XMLELEMENT(NAME element, XMLATTRIBUTES(1 AS ":one:", 'deuce' AS two), 'content&') AS "xmlelement";
- xmlview4 | SELECT XMLELEMENT(NAME employee, XMLFOREST(name AS name, age AS age, salary AS pay)) AS "xmlelement" +
+ xmlview4 | SELECT XMLELEMENT(NAME employee, XMLFOREST(name AS name, age AS age, salary AS pay)) AS "xmlelement" +
| FROM emp;
xmlview5 | SELECT XMLPARSE(CONTENT 'x'::text STRIP WHITESPACE) AS "xmlparse";
xmlview6 | SELECT XMLPI(NAME foo, 'bar'::text) AS "xmlpi";
xmlview7 | SELECT XMLROOT(''::xml, VERSION NO VALUE, STANDALONE YES) AS "xmlroot";
xmlview8 | SELECT (XMLSERIALIZE(CONTENT 'good'::xml AS character(10) NO INDENT))::character(10) AS "xmlserialize";
xmlview9 | SELECT XMLSERIALIZE(CONTENT 'good'::xml AS text NO INDENT) AS "xmlserialize";
-(11 rows)
+(20 rows)
-- Text XPath expressions evaluation
SELECT xpath('/value', data) FROM xmltest;
diff --git a/src/test/regress/sql/xml.sql b/src/test/regress/sql/xml.sql
index 0ea4f508837c..e12683353efc 100644
--- a/src/test/regress/sql/xml.sql
+++ b/src/test/regress/sql/xml.sql
@@ -172,6 +172,78 @@ SELECT xmlserialize(CONTENT '42' AS text
SELECT xmlserialize(DOCUMENT ' ' AS text INDENT);
SELECT xmlserialize(CONTENT 'text node ' AS text INDENT);
+-- 'including xmldeclaration' and 'excluding xmldeclaration'(DOCUMENT)
+SELECT xmlserialize(DOCUMENT '42'::xml AS text INCLUDING XMLDECLARATION);
+SELECT xmlserialize(DOCUMENT '42'::xml AS text EXCLUDING XMLDECLARATION);
+SELECT xmlserialize(DOCUMENT '42'::xml AS text INCLUDING XMLDECLARATION);
+SELECT xmlserialize(DOCUMENT '42'::xml AS text EXCLUDING XMLDECLARATION);
+SELECT xmlserialize(DOCUMENT '42'::xml AS text INCLUDING XMLDECLARATION);
+SELECT xmlserialize(DOCUMENT '42'::xml AS text INCLUDING XMLDECLARATION);
+-- 'including xmldeclaration' and 'excluding xmldeclaration'(CONTENT)
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text INCLUDING XMLDECLARATION);
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text EXCLUDING XMLDECLARATION);
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text INCLUDING XMLDECLARATION);
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text EXCLUDING XMLDECLARATION);
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text INCLUDING XMLDECLARATION);
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text INCLUDING XMLDECLARATION);
+-- 'indent' + 'including xmldeclaration' and 'excluding xmldeclaration' (DOCUMENT)
+SELECT xmlserialize(DOCUMENT '42'::xml AS text INCLUDING XMLDECLARATION INDENT);
+SELECT xmlserialize(DOCUMENT '42'::xml AS text EXCLUDING XMLDECLARATION INDENT);
+SELECT xmlserialize(DOCUMENT '42'::xml AS text INCLUDING XMLDECLARATION INDENT);
+SELECT xmlserialize(DOCUMENT '42'::xml AS text EXCLUDING XMLDECLARATION INDENT);
+SELECT xmlserialize(DOCUMENT '42'::xml AS text INCLUDING XMLDECLARATION INDENT);
+SELECT xmlserialize(DOCUMENT '42'::xml AS text INCLUDING XMLDECLARATION INDENT);
+-- 'indent' + 'including xmldeclaration' and 'excluding xmldeclaration'(CONTENT)
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text INCLUDING XMLDECLARATION INDENT);
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text EXCLUDING XMLDECLARATION INDENT);
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text INCLUDING XMLDECLARATION INDENT);
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text EXCLUDING XMLDECLARATION INDENT);
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text INCLUDING XMLDECLARATION INDENT);
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text INCLUDING XMLDECLARATION INDENT);
+-- 'version' + 'including xmldeclaration' and 'excluding xmldeclaration'(DOCUMENT)
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.0');
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.0' INCLUDING XMLDECLARATION);
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.0');
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.0' INCLUDING XMLDECLARATION);
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.1' EXCLUDING XMLDECLARATION);
+-- 'version' + 'including xmldeclaration' and 'excluding xmldeclaration'(CONTENT)
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION '1.1');
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION '1.1' INCLUDING XMLDECLARATION);
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION '1.1');
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION '1.1' INCLUDING XMLDECLARATION);
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION '1.1' EXCLUDING XMLDECLARATION);
+-- 'version' + 'indent' (DOCUMENT)
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.0' INDENT);
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.0' INDENT);
+-- 'indent' + 'version' (CONTENT)
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION '1.1' INDENT);
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION '1.1' INDENT);
+-- 'indent' + 'version' + 'including xmldeclaration' and 'excluding xmldeclaration'(DOCUMENT)
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.0' INCLUDING XMLDECLARATION INDENT);
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.0' INCLUDING XMLDECLARATION INDENT);
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.0' EXCLUDING XMLDECLARATION INDENT);
+-- 'indent' + 'version' + 'including xmldeclaration' and 'excluding xmldeclaration'(CONTENT)
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION '1.1' INCLUDING XMLDECLARATION INDENT);
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION '1.1' INCLUDING XMLDECLARATION INDENT);
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION '1.1' EXCLUDING XMLDECLARATION INDENT);
+--'version' with null value (DOCUMENT)
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION NULL);
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION NULL EXCLUDING XMLDECLARATION);
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION NULL INCLUDING XMLDECLARATION);
+--'version' with null value (CONTENT)
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION NULL);
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION NULL EXCLUDING XMLDECLARATION);
+SELECT xmlserialize(CONTENT 'txt42'::xml AS text VERSION NULL INCLUDING XMLDECLARATION);
+
+-- 'version' + 'including xmldeclaration' warning and error messages
+\set VERBOSITY terse
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '1.1' INCLUDING XMLDECLARATION);
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '2.0' INCLUDING XMLDECLARATION);
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION '' INCLUDING XMLDECLARATION);
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION ' ' INCLUDING XMLDECLARATION);
+SELECT xmlserialize(DOCUMENT '42'::xml AS text VERSION 'foo' INCLUDING XMLDECLARATION);
+\set VERBOSITY default
+
SELECT xml 'bar' IS DOCUMENT;
SELECT xml 'barfoo' IS DOCUMENT;
SELECT xml '' IS NOT DOCUMENT;
@@ -221,6 +293,15 @@ CREATE VIEW xmlview8 AS SELECT xmlserialize(content 'good' as char(10));
CREATE VIEW xmlview9 AS SELECT xmlserialize(content 'good' as text);
CREATE VIEW xmlview10 AS SELECT xmlserialize(document '42' AS text indent);
CREATE VIEW xmlview11 AS SELECT xmlserialize(document '42' AS character varying no indent);
+CREATE VIEW xmlview12 AS SELECT xmlserialize(document '42' AS text including xmldeclaration);
+CREATE VIEW xmlview13 AS SELECT xmlserialize(document '42' AS text excluding xmldeclaration);
+CREATE VIEW xmlview14 AS SELECT xmlserialize(document '42' AS text including xmldeclaration indent);
+CREATE VIEW xmlview15 AS SELECT xmlserialize(document '42' AS text excluding xmldeclaration indent);
+CREATE VIEW xmlview16 AS SELECT xmlserialize(document '42' AS text including xmldeclaration no indent);
+CREATE VIEW xmlview17 AS SELECT xmlserialize(document '42' AS text excluding xmldeclaration no indent);
+CREATE VIEW xmlview18 AS SELECT xmlserialize(document '42' AS text version '1.0' including xmldeclaration indent);
+CREATE VIEW xmlview19 AS SELECT xmlserialize(document '42' AS text version '1.0' including xmldeclaration no indent);
+CREATE VIEW xmlview20 AS SELECT xmlserialize(document '42' AS text version '1.0');
SELECT table_name, view_definition FROM information_schema.views
WHERE table_name LIKE 'xmlview%' ORDER BY 1;