diff options
| author | Peter Eisentraut | 2007-02-03 14:06:56 +0000 |
|---|---|---|
| committer | Peter Eisentraut | 2007-02-03 14:06:56 +0000 |
| commit | ec020e1ceb94d0ceb3c0eee8c39cd197be7bb3cb (patch) | |
| tree | 99f52eea439dd239d8e9a7f04f70f567b88ee798 /src/test | |
| parent | 25dc46334b99f3161d931a608fb49f6eced42065 (diff) | |
Implement XMLSERIALIZE for real. Analogously, make the xml to text cast
observe the xmloption.
Reorganize the representation of the XML option in the parse tree and the
API to make it easier to manage and understand.
Add regression tests for parsing back XML expressions.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/regress/expected/opr_sanity.out | 7 | ||||
| -rw-r--r-- | src/test/regress/expected/xml.out | 36 | ||||
| -rw-r--r-- | src/test/regress/expected/xml_1.out | 34 | ||||
| -rw-r--r-- | src/test/regress/sql/opr_sanity.sql | 3 | ||||
| -rw-r--r-- | src/test/regress/sql/xml.sql | 20 |
5 files changed, 85 insertions, 15 deletions
diff --git a/src/test/regress/expected/opr_sanity.out b/src/test/regress/expected/opr_sanity.out index 33bebcfa66a..fcbfe3cad51 100644 --- a/src/test/regress/expected/opr_sanity.out +++ b/src/test/regress/expected/opr_sanity.out @@ -288,8 +288,6 @@ WHERE c.castfunc = p.oid AND -- those are binary-compatible while the reverse way goes through rtrim(). -- As of 8.2, this finds the cast from cidr to inet, because that is a -- trivial binary coercion while the other way goes through inet_to_cidr(). --- As of 8.3, this finds casts from xml to text, varchar, and bpchar, --- because the other direction has to go through xmlparse(). SELECT * FROM pg_cast c WHERE c.castfunc = 0 AND @@ -302,10 +300,7 @@ WHERE c.castfunc = 0 AND 25 | 1042 | 0 | i 1043 | 1042 | 0 | i 650 | 869 | 0 | i - 142 | 25 | 0 | e - 142 | 1043 | 0 | e - 142 | 1042 | 0 | e -(6 rows) +(3 rows) -- **************** pg_operator **************** -- Look for illegal values in pg_operator fields. diff --git a/src/test/regress/expected/xml.out b/src/test/regress/expected/xml.out index 0c086677068..6d79a4166e7 100644 --- a/src/test/regress/expected/xml.out +++ b/src/test/regress/expected/xml.out @@ -275,13 +275,21 @@ SELECT xmlroot ( <?xml version="1.0" standalone="yes"?><gazonk name="val" num="2"><qux>foo</qux></gazonk> (1 row) -SELECT xmlserialize(content data as character varying) FROM xmltest; - data +SELECT xmlserialize(content data as character varying(20)) FROM xmltest; + xmlserialize -------------------- <value>one</value> <value>two</value> (2 rows) +SELECT xmlserialize(content 'good' as char(10)); + xmlserialize +-------------- + good +(1 row) + +SELECT xmlserialize(document 'bad' as text); +ERROR: not an XML document SELECT xml '<foo>bar</foo>' IS DOCUMENT; ?column? ---------- @@ -368,3 +376,27 @@ EXECUTE foo ('good'); <foo/>good (1 row) +-- Test backwards parsing +CREATE VIEW xmlview1 AS SELECT xmlcomment('test'); +CREATE VIEW xmlview2 AS SELECT xmlconcat('hello', 'you'); +CREATE VIEW xmlview3 AS SELECT xmlelement(name element, xmlattributes (1 as ":one:", 'deuce' as two), 'content&'); +CREATE VIEW xmlview4 AS SELECT xmlelement(name employee, xmlforest(name, age, salary as pay)) FROM emp; +CREATE VIEW xmlview5 AS SELECT xmlparse(content '<abc>x</abc>'); +CREATE VIEW xmlview6 AS SELECT xmlpi(name foo, 'bar'); +CREATE VIEW xmlview7 AS SELECT xmlroot(xml '<foo/>', version no value, standalone yes); +CREATE VIEW xmlview8 AS SELECT xmlserialize(content 'good' as char(10)); +CREATE VIEW xmlview9 AS SELECT xmlserialize(content 'good' as text); +SELECT table_name, view_definition FROM information_schema.views WHERE table_name LIKE 'xmlview%'; + table_name | view_definition +------------+-------------------------------------------------------------------------------------------------------------------------------- + xmlview1 | SELECT xmlcomment('test'::text) AS xmlcomment; + xmlview2 | SELECT XMLCONCAT('hello'::"xml", 'you'::"xml") AS "xmlconcat"; + xmlview3 | SELECT XMLELEMENT(NAME element, XMLATTRIBUTES(1 AS ":one:", 'deuce' AS two), 'content&') AS "xmlelement"; + xmlview4 | SELECT XMLELEMENT(NAME employee, XMLFOREST(emp."name" AS "name", emp.age AS age, emp.salary AS pay)) AS "xmlelement" FROM emp; + xmlview5 | SELECT XMLPARSE(CONTENT '<abc>x</abc>'::text STRIP WHITESPACE) AS "xmlparse"; + xmlview6 | SELECT XMLPI(NAME foo, 'bar'::text) AS "xmlpi"; + xmlview7 | SELECT XMLROOT('<foo/>'::"xml", VERSION NO VALUE, STANDALONE YES) AS "xmlroot"; + xmlview8 | SELECT (XMLSERIALIZE(CONTENT 'good'::"xml" AS character(10)))::character(10) AS "xmlserialize"; + xmlview9 | SELECT XMLSERIALIZE(CONTENT 'good'::"xml" AS text) AS "xmlserialize"; +(9 rows) + diff --git a/src/test/regress/expected/xml_1.out b/src/test/regress/expected/xml_1.out index 89124ebb98e..899ed4cd266 100644 --- a/src/test/regress/expected/xml_1.out +++ b/src/test/regress/expected/xml_1.out @@ -122,11 +122,15 @@ SELECT xmlroot ( standalone yes ); ERROR: no XML support in this installation -SELECT xmlserialize(content data as character varying) FROM xmltest; - data ------- +SELECT xmlserialize(content data as character varying(20)) FROM xmltest; + xmlserialize +-------------- (0 rows) +SELECT xmlserialize(content 'good' as char(10)); +ERROR: no XML support in this installation +SELECT xmlserialize(document 'bad' as text); +ERROR: no XML support in this installation SELECT xml '<foo>bar</foo>' IS DOCUMENT; ERROR: no XML support in this installation SELECT xml '<foo>bar</foo><bar>foo</bar>' IS DOCUMENT; @@ -168,3 +172,27 @@ EXECUTE foo ('<bar/>'); ERROR: prepared statement "foo" does not exist EXECUTE foo ('good'); ERROR: prepared statement "foo" does not exist +-- Test backwards parsing +CREATE VIEW xmlview1 AS SELECT xmlcomment('test'); +CREATE VIEW xmlview2 AS SELECT xmlconcat('hello', 'you'); +ERROR: no XML support in this installation +CREATE VIEW xmlview3 AS SELECT xmlelement(name element, xmlattributes (1 as ":one:", 'deuce' as two), 'content&'); +ERROR: no XML support in this installation +CREATE VIEW xmlview4 AS SELECT xmlelement(name employee, xmlforest(name, age, salary as pay)) FROM emp; +ERROR: no XML support in this installation +CREATE VIEW xmlview5 AS SELECT xmlparse(content '<abc>x</abc>'); +CREATE VIEW xmlview6 AS SELECT xmlpi(name foo, 'bar'); +ERROR: no XML support in this installation +CREATE VIEW xmlview7 AS SELECT xmlroot(xml '<foo/>', version no value, standalone yes); +ERROR: no XML support in this installation +CREATE VIEW xmlview8 AS SELECT xmlserialize(content 'good' as char(10)); +ERROR: no XML support in this installation +CREATE VIEW xmlview9 AS SELECT xmlserialize(content 'good' as text); +ERROR: no XML support in this installation +SELECT table_name, view_definition FROM information_schema.views WHERE table_name LIKE 'xmlview%'; + table_name | view_definition +------------+------------------------------------------------------------------------------- + xmlview1 | SELECT xmlcomment('test'::text) AS xmlcomment; + xmlview5 | SELECT XMLPARSE(CONTENT '<abc>x</abc>'::text STRIP WHITESPACE) AS "xmlparse"; +(2 rows) + diff --git a/src/test/regress/sql/opr_sanity.sql b/src/test/regress/sql/opr_sanity.sql index 7eff2195dfb..cbf9baf6728 100644 --- a/src/test/regress/sql/opr_sanity.sql +++ b/src/test/regress/sql/opr_sanity.sql @@ -238,9 +238,6 @@ WHERE c.castfunc = p.oid AND -- As of 8.2, this finds the cast from cidr to inet, because that is a -- trivial binary coercion while the other way goes through inet_to_cidr(). --- As of 8.3, this finds casts from xml to text, varchar, and bpchar, --- because the other direction has to go through xmlparse(). - SELECT * FROM pg_cast c WHERE c.castfunc = 0 AND diff --git a/src/test/regress/sql/xml.sql b/src/test/regress/sql/xml.sql index b3117c2424f..2f919fb42a0 100644 --- a/src/test/regress/sql/xml.sql +++ b/src/test/regress/sql/xml.sql @@ -68,6 +68,7 @@ SELECT xmlpi(name foo, null); SELECT xmlpi(name xmlstuff, null); SELECT xmlpi(name foo, ' bar'); + SELECT xmlroot(xml '<foo/>', version no value, standalone no value); SELECT xmlroot(xml '<foo/>', version '2.0'); SELECT xmlroot(xml '<foo/>', version no value, standalone yes); @@ -95,7 +96,9 @@ SELECT xmlroot ( ); -SELECT xmlserialize(content data as character varying) FROM xmltest; +SELECT xmlserialize(content data as character varying(20)) FROM xmltest; +SELECT xmlserialize(content 'good' as char(10)); +SELECT xmlserialize(document 'bad' as text); SELECT xml '<foo>bar</foo>' IS DOCUMENT; @@ -125,3 +128,18 @@ EXECUTE foo ('bad'); SET XML OPTION CONTENT; EXECUTE foo ('<bar/>'); EXECUTE foo ('good'); + + +-- Test backwards parsing + +CREATE VIEW xmlview1 AS SELECT xmlcomment('test'); +CREATE VIEW xmlview2 AS SELECT xmlconcat('hello', 'you'); +CREATE VIEW xmlview3 AS SELECT xmlelement(name element, xmlattributes (1 as ":one:", 'deuce' as two), 'content&'); +CREATE VIEW xmlview4 AS SELECT xmlelement(name employee, xmlforest(name, age, salary as pay)) FROM emp; +CREATE VIEW xmlview5 AS SELECT xmlparse(content '<abc>x</abc>'); +CREATE VIEW xmlview6 AS SELECT xmlpi(name foo, 'bar'); +CREATE VIEW xmlview7 AS SELECT xmlroot(xml '<foo/>', version no value, standalone yes); +CREATE VIEW xmlview8 AS SELECT xmlserialize(content 'good' as char(10)); +CREATE VIEW xmlview9 AS SELECT xmlserialize(content 'good' as text); + +SELECT table_name, view_definition FROM information_schema.views WHERE table_name LIKE 'xmlview%'; |
