diff options
| author | Daniel Gustafsson | 2023-11-06 08:38:29 +0000 |
|---|---|---|
| committer | Daniel Gustafsson | 2023-11-06 08:38:29 +0000 |
| commit | 526fe0d79914b2dfcfd79effd1ab26ff62469248 (patch) | |
| tree | 7d25dbd45a49eeba488ae7d1f57520babda7e336 /src/test | |
| parent | 7b5275eec3a50d55f5750357b8a223cf5f0bb59f (diff) | |
Add XMLText function (SQL/XML X038)
This function implements the standard XMLTest function, which
converts text into xml text nodes. It uses the libxml2 function
xmlEncodeSpecialChars to escape predefined entities (&"<>), so
that those do not cause any conflict when concatenating the text
node output with existing xml documents.
This also adds a note in features.sgml about not supporting
XML(SEQUENCE). The SQL specification defines a RETURNING clause
to a set of XML functions, where RETURNING CONTENT or RETURNING
SEQUENCE can be defined. Since PostgreSQL doesn't support
XML(SEQUENCE) all of these functions operate with an
implicit RETURNING CONTENT.
Author: Jim Jones <[email protected]>
Reviewed-by: Vik Fearing <[email protected]>
Discussion: https://postgr.es/m/[email protected]
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/regress/expected/xml.out | 36 | ||||
| -rw-r--r-- | src/test/regress/expected/xml_1.out | 23 | ||||
| -rw-r--r-- | src/test/regress/expected/xml_2.out | 36 | ||||
| -rw-r--r-- | src/test/regress/sql/xml.sql | 7 |
4 files changed, 102 insertions, 0 deletions
diff --git a/src/test/regress/expected/xml.out b/src/test/regress/expected/xml.out index 398345ca67f..13e4296bf8f 100644 --- a/src/test/regress/expected/xml.out +++ b/src/test/regress/expected/xml.out @@ -1785,3 +1785,39 @@ SELECT * FROM XMLTABLE('.' PASSING XMLELEMENT(NAME a) columns a varchar(20) PATH <foo/> | <foo/> (1 row) +SELECT xmltext(NULL); + xmltext +--------- + +(1 row) + +SELECT xmltext(''); + xmltext +--------- + +(1 row) + +SELECT xmltext(' '); + xmltext +--------- + +(1 row) + +SELECT xmltext('foo `$_-+?=*^%!|/\()[]{}'); + xmltext +-------------------------- + foo `$_-+?=*^%!|/\()[]{} +(1 row) + +SELECT xmltext('foo & <"bar">'); + xmltext +----------------------------------- + foo & <"bar"> +(1 row) + +SELECT xmltext('x'|| '<P>73</P>'::xml || .42 || true || 'j'::char); + xmltext +--------------------------------- + x<P>73</P>0.42truej +(1 row) + diff --git a/src/test/regress/expected/xml_1.out b/src/test/regress/expected/xml_1.out index 63b779470ff..eb9c6f2ed41 100644 --- a/src/test/regress/expected/xml_1.out +++ b/src/test/regress/expected/xml_1.out @@ -1402,3 +1402,26 @@ DETAIL: This functionality requires the server to be built with libxml support. SELECT * FROM XMLTABLE('.' PASSING XMLELEMENT(NAME a) columns a varchar(20) PATH '"<foo/>"', b xml PATH '"<foo/>"'); ERROR: unsupported XML feature DETAIL: This functionality requires the server to be built with libxml support. +SELECT xmltext(NULL); + xmltext +--------- + +(1 row) + +SELECT xmltext(''); +ERROR: unsupported XML feature +DETAIL: This functionality requires the server to be built with libxml support. +SELECT xmltext(' '); +ERROR: unsupported XML feature +DETAIL: This functionality requires the server to be built with libxml support. +SELECT xmltext('foo `$_-+?=*^%!|/\()[]{}'); +ERROR: unsupported XML feature +DETAIL: This functionality requires the server to be built with libxml support. +SELECT xmltext('foo & <"bar">'); +ERROR: unsupported XML feature +DETAIL: This functionality requires the server to be built with libxml support. +SELECT xmltext('x'|| '<P>73</P>'::xml || .42 || true || 'j'::char); +ERROR: unsupported XML feature +LINE 1: SELECT xmltext('x'|| '<P>73</P>'::xml || .42 || true || 'j':... + ^ +DETAIL: This functionality requires the server to be built with libxml support. diff --git a/src/test/regress/expected/xml_2.out b/src/test/regress/expected/xml_2.out index 43c2558352a..c8ed8e0cfa6 100644 --- a/src/test/regress/expected/xml_2.out +++ b/src/test/regress/expected/xml_2.out @@ -1765,3 +1765,39 @@ SELECT * FROM XMLTABLE('.' PASSING XMLELEMENT(NAME a) columns a varchar(20) PATH <foo/> | <foo/> (1 row) +SELECT xmltext(NULL); + xmltext +--------- + +(1 row) + +SELECT xmltext(''); + xmltext +--------- + +(1 row) + +SELECT xmltext(' '); + xmltext +--------- + +(1 row) + +SELECT xmltext('foo `$_-+?=*^%!|/\()[]{}'); + xmltext +-------------------------- + foo `$_-+?=*^%!|/\()[]{} +(1 row) + +SELECT xmltext('foo & <"bar">'); + xmltext +----------------------------------- + foo & <"bar"> +(1 row) + +SELECT xmltext('x'|| '<P>73</P>'::xml || .42 || true || 'j'::char); + xmltext +--------------------------------- + x<P>73</P>0.42truej +(1 row) + diff --git a/src/test/regress/sql/xml.sql b/src/test/regress/sql/xml.sql index a591eea2e5d..bd4a4e7acdf 100644 --- a/src/test/regress/sql/xml.sql +++ b/src/test/regress/sql/xml.sql @@ -660,3 +660,10 @@ SELECT * FROM XMLTABLE('*' PASSING '<e>pre<!--c1--><?pi arg?><![CDATA[&ent1]]><n \x SELECT * FROM XMLTABLE('.' PASSING XMLELEMENT(NAME a) columns a varchar(20) PATH '"<foo/>"', b xml PATH '"<foo/>"'); + +SELECT xmltext(NULL); +SELECT xmltext(''); +SELECT xmltext(' '); +SELECT xmltext('foo `$_-+?=*^%!|/\()[]{}'); +SELECT xmltext('foo & <"bar">'); +SELECT xmltext('x'|| '<P>73</P>'::xml || .42 || true || 'j'::char);
\ No newline at end of file |
