diff options
| author | Tom Lane | 2011-07-21 15:32:46 +0000 |
|---|---|---|
| committer | Tom Lane | 2011-07-21 15:32:46 +0000 |
| commit | 0ce7676aa03a2501fde949fea211ba5cd84c2ded (patch) | |
| tree | 792173ad0b228f5a08db6aa3edb0dad38dad7aee /src/test | |
| parent | aaf15e5c1cf8d2c27d2f9841343f00027762cb4e (diff) | |
Make xpath() do something useful with XPath expressions that return scalars.
Previously, xpath() simply returned an empty array if the expression did
not yield a node set. This is useless for expressions that return scalars,
such as one with name() at the top level. Arrange to return the scalar
value as a single-element xml array, instead. (String values will be
suitably escaped.)
This change will also cause xpath_exists() to return true, not false,
for such expressions.
Florian Pflug, reviewed by Radoslaw Smogura
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/regress/expected/xml.out | 48 | ||||
| -rw-r--r-- | src/test/regress/expected/xml_1.out | 48 | ||||
| -rw-r--r-- | src/test/regress/sql/xml.sql | 8 |
3 files changed, 104 insertions, 0 deletions
diff --git a/src/test/regress/expected/xml.out b/src/test/regress/expected/xml.out index 5cd602107b2..5dfa44b5b99 100644 --- a/src/test/regress/expected/xml.out +++ b/src/test/regress/expected/xml.out @@ -601,6 +601,42 @@ SELECT xpath('//@value', '<root value="<"/>'); {<} (1 row) +SELECT xpath('''<<invalid>>''', '<root/>'); + xpath +--------------------------- + {<<invalid>>} +(1 row) + +SELECT xpath('count(//*)', '<root><sub/><sub/></root>'); + xpath +------- + {3} +(1 row) + +SELECT xpath('count(//*)=0', '<root><sub/><sub/></root>'); + xpath +--------- + {false} +(1 row) + +SELECT xpath('count(//*)=3', '<root><sub/><sub/></root>'); + xpath +-------- + {true} +(1 row) + +SELECT xpath('name(/*)', '<root><sub/><sub/></root>'); + xpath +-------- + {root} +(1 row) + +SELECT xpath('/nosuchtag', '<root/>'); + xpath +------- + {} +(1 row) + -- Test xmlexists and xpath_exists SELECT xmlexists('//town[text() = ''Toronto'']' PASSING BY REF '<towns><town>Bidford-on-Avon</town><town>Cwmbran</town><town>Bristol</town></towns>'); xmlexists @@ -614,6 +650,12 @@ SELECT xmlexists('//town[text() = ''Cwmbran'']' PASSING BY REF '<towns><town>Bid t (1 row) +SELECT xmlexists('count(/nosuchtag)' PASSING BY REF '<root/>'); + xmlexists +----------- + t +(1 row) + SELECT xpath_exists('//town[text() = ''Toronto'']','<towns><town>Bidford-on-Avon</town><town>Cwmbran</town><town>Bristol</town></towns>'::xml); xpath_exists -------------- @@ -626,6 +668,12 @@ SELECT xpath_exists('//town[text() = ''Cwmbran'']','<towns><town>Bidford-on-Avon t (1 row) +SELECT xpath_exists('count(/nosuchtag)', '<root/>'::xml); + xpath_exists +-------------- + t +(1 row) + INSERT INTO xmltest VALUES (4, '<menu><beers><name>Budvar</name><cost>free</cost><name>Carling</name><cost>lots</cost></beers></menu>'::xml); INSERT INTO xmltest VALUES (5, '<menu><beers><name>Molson</name><cost>free</cost><name>Carling</name><cost>lots</cost></beers></menu>'::xml); INSERT INTO xmltest VALUES (6, '<myns:menu xmlns:myns="http://myns.com"><myns:beers><myns:name>Budvar</myns:name><myns:cost>free</myns:cost><myns:name>Carling</myns:name><myns:cost>lots</myns:cost></myns:beers></myns:menu>'::xml); diff --git a/src/test/regress/expected/xml_1.out b/src/test/regress/expected/xml_1.out index 53675f5536f..c6c0e7ac887 100644 --- a/src/test/regress/expected/xml_1.out +++ b/src/test/regress/expected/xml_1.out @@ -516,6 +516,42 @@ LINE 1: SELECT xpath('//@value', '<root value="<"/>'); ^ DETAIL: This functionality requires the server to be built with libxml support. HINT: You need to rebuild PostgreSQL using --with-libxml. +SELECT xpath('''<<invalid>>''', '<root/>'); +ERROR: unsupported XML feature +LINE 1: SELECT xpath('''<<invalid>>''', '<root/>'); + ^ +DETAIL: This functionality requires the server to be built with libxml support. +HINT: You need to rebuild PostgreSQL using --with-libxml. +SELECT xpath('count(//*)', '<root><sub/><sub/></root>'); +ERROR: unsupported XML feature +LINE 1: SELECT xpath('count(//*)', '<root><sub/><sub/></root>'); + ^ +DETAIL: This functionality requires the server to be built with libxml support. +HINT: You need to rebuild PostgreSQL using --with-libxml. +SELECT xpath('count(//*)=0', '<root><sub/><sub/></root>'); +ERROR: unsupported XML feature +LINE 1: SELECT xpath('count(//*)=0', '<root><sub/><sub/></root>'); + ^ +DETAIL: This functionality requires the server to be built with libxml support. +HINT: You need to rebuild PostgreSQL using --with-libxml. +SELECT xpath('count(//*)=3', '<root><sub/><sub/></root>'); +ERROR: unsupported XML feature +LINE 1: SELECT xpath('count(//*)=3', '<root><sub/><sub/></root>'); + ^ +DETAIL: This functionality requires the server to be built with libxml support. +HINT: You need to rebuild PostgreSQL using --with-libxml. +SELECT xpath('name(/*)', '<root><sub/><sub/></root>'); +ERROR: unsupported XML feature +LINE 1: SELECT xpath('name(/*)', '<root><sub/><sub/></root>'); + ^ +DETAIL: This functionality requires the server to be built with libxml support. +HINT: You need to rebuild PostgreSQL using --with-libxml. +SELECT xpath('/nosuchtag', '<root/>'); +ERROR: unsupported XML feature +LINE 1: SELECT xpath('/nosuchtag', '<root/>'); + ^ +DETAIL: This functionality requires the server to be built with libxml support. +HINT: You need to rebuild PostgreSQL using --with-libxml. -- Test xmlexists and xpath_exists SELECT xmlexists('//town[text() = ''Toronto'']' PASSING BY REF '<towns><town>Bidford-on-Avon</town><town>Cwmbran</town><town>Bristol</town></towns>'); ERROR: unsupported XML feature @@ -529,6 +565,12 @@ LINE 1: ...sts('//town[text() = ''Cwmbran'']' PASSING BY REF '<towns><t... ^ DETAIL: This functionality requires the server to be built with libxml support. HINT: You need to rebuild PostgreSQL using --with-libxml. +SELECT xmlexists('count(/nosuchtag)' PASSING BY REF '<root/>'); +ERROR: unsupported XML feature +LINE 1: ...LECT xmlexists('count(/nosuchtag)' PASSING BY REF '<root/>')... + ^ +DETAIL: This functionality requires the server to be built with libxml support. +HINT: You need to rebuild PostgreSQL using --with-libxml. SELECT xpath_exists('//town[text() = ''Toronto'']','<towns><town>Bidford-on-Avon</town><town>Cwmbran</town><town>Bristol</town></towns>'::xml); ERROR: unsupported XML feature LINE 1: ...ELECT xpath_exists('//town[text() = ''Toronto'']','<towns><t... @@ -541,6 +583,12 @@ LINE 1: ...ELECT xpath_exists('//town[text() = ''Cwmbran'']','<towns><t... ^ DETAIL: This functionality requires the server to be built with libxml support. HINT: You need to rebuild PostgreSQL using --with-libxml. +SELECT xpath_exists('count(/nosuchtag)', '<root/>'::xml); +ERROR: unsupported XML feature +LINE 1: SELECT xpath_exists('count(/nosuchtag)', '<root/>'::xml); + ^ +DETAIL: This functionality requires the server to be built with libxml support. +HINT: You need to rebuild PostgreSQL using --with-libxml. INSERT INTO xmltest VALUES (4, '<menu><beers><name>Budvar</name><cost>free</cost><name>Carling</name><cost>lots</cost></beers></menu>'::xml); ERROR: unsupported XML feature LINE 1: INSERT INTO xmltest VALUES (4, '<menu><beers><name>Budvar</n... diff --git a/src/test/regress/sql/xml.sql b/src/test/regress/sql/xml.sql index 3270e157214..3623dbc254e 100644 --- a/src/test/regress/sql/xml.sql +++ b/src/test/regress/sql/xml.sql @@ -177,12 +177,20 @@ SELECT xpath('//loc:piece/@id', '<local:data xmlns:local="http://127.0.0.1"><loc SELECT xpath('//b', '<a>one <b>two</b> three <b>etc</b></a>'); SELECT xpath('//text()', '<root><</root>'); SELECT xpath('//@value', '<root value="<"/>'); +SELECT xpath('''<<invalid>>''', '<root/>'); +SELECT xpath('count(//*)', '<root><sub/><sub/></root>'); +SELECT xpath('count(//*)=0', '<root><sub/><sub/></root>'); +SELECT xpath('count(//*)=3', '<root><sub/><sub/></root>'); +SELECT xpath('name(/*)', '<root><sub/><sub/></root>'); +SELECT xpath('/nosuchtag', '<root/>'); -- Test xmlexists and xpath_exists SELECT xmlexists('//town[text() = ''Toronto'']' PASSING BY REF '<towns><town>Bidford-on-Avon</town><town>Cwmbran</town><town>Bristol</town></towns>'); SELECT xmlexists('//town[text() = ''Cwmbran'']' PASSING BY REF '<towns><town>Bidford-on-Avon</town><town>Cwmbran</town><town>Bristol</town></towns>'); +SELECT xmlexists('count(/nosuchtag)' PASSING BY REF '<root/>'); SELECT xpath_exists('//town[text() = ''Toronto'']','<towns><town>Bidford-on-Avon</town><town>Cwmbran</town><town>Bristol</town></towns>'::xml); SELECT xpath_exists('//town[text() = ''Cwmbran'']','<towns><town>Bidford-on-Avon</town><town>Cwmbran</town><town>Bristol</town></towns>'::xml); +SELECT xpath_exists('count(/nosuchtag)', '<root/>'::xml); INSERT INTO xmltest VALUES (4, '<menu><beers><name>Budvar</name><cost>free</cost><name>Carling</name><cost>lots</cost></beers></menu>'::xml); INSERT INTO xmltest VALUES (5, '<menu><beers><name>Molson</name><cost>free</cost><name>Carling</name><cost>lots</cost></beers></menu>'::xml); |
