]> granicus.if.org Git - postgresql/blob - src/test/regress/sql/xml.sql
Fix crash of xmlconcat(NULL)
[postgresql] / src / test / regress / sql / xml.sql
1 CREATE TABLE xmltest (
2     id int,
3     data xml
4 );
5
6 INSERT INTO xmltest VALUES (1, '<value>one</value>');
7 INSERT INTO xmltest VALUES (2, '<value>two</value>');
8 INSERT INTO xmltest VALUES (3, '<wrong');
9
10 SELECT * FROM xmltest;
11
12
13 SELECT xmlcomment('test');
14 SELECT xmlcomment('-test');
15 SELECT xmlcomment('test-');
16 SELECT xmlcomment('--test');
17 SELECT xmlcomment('te st');
18
19
20 SELECT xmlconcat(xmlcomment('hello'),
21                  xmlelement(NAME qux, 'foo'),
22                  xmlcomment('world'));
23
24 SELECT xmlconcat('hello', 'you');
25 SELECT xmlconcat(1, 2);
26 SELECT xmlconcat('bad', '<syntax');
27 SELECT xmlconcat('<foo/>', NULL, '<?xml version="1.1" standalone="no"?><bar/>');
28 SELECT xmlconcat('<?xml version="1.1"?><foo/>', NULL, '<?xml version="1.1" standalone="no"?><bar/>');
29 SELECT xmlconcat(NULL);
30 SELECT xmlconcat(NULL, NULL);
31
32
33 SELECT xmlelement(name element,
34                   xmlattributes (1 as one, 'deuce' as two),
35                   'content');
36
37 SELECT xmlelement(name element,
38                   xmlattributes ('unnamed and wrong'));
39
40 SELECT xmlelement(name element, xmlelement(name nested, 'stuff'));
41
42 SELECT xmlelement(name employee, xmlforest(name, age, salary as pay)) FROM emp;
43
44 SELECT xmlelement(name duplicate, xmlattributes(1 as a, 2 as b, 3 as a));
45
46 SELECT xmlelement(name num, 37);
47 SELECT xmlelement(name foo, text 'bar');
48 SELECT xmlelement(name foo, xml 'bar');
49 SELECT xmlelement(name foo, text 'b<a/>r');
50 SELECT xmlelement(name foo, xml 'b<a/>r');
51 SELECT xmlelement(name foo, array[1, 2, 3]);
52 SET xmlbinary TO base64;
53 SELECT xmlelement(name foo, bytea 'bar');
54 SET xmlbinary TO hex;
55 SELECT xmlelement(name foo, bytea 'bar');
56
57
58 SELECT xmlparse(content 'abc');
59 SELECT xmlparse(content '<abc>x</abc>');
60
61 SELECT xmlparse(document 'abc');
62 SELECT xmlparse(document '<abc>x</abc>');
63
64
65 SELECT xmlpi(name foo);
66 SELECT xmlpi(name xml);
67 SELECT xmlpi(name xmlstuff);
68 SELECT xmlpi(name foo, 'bar');
69 SELECT xmlpi(name foo, 'in?>valid');
70 SELECT xmlpi(name foo, null);
71 SELECT xmlpi(name xml, null);
72 SELECT xmlpi(name xmlstuff, null);
73 SELECT xmlpi(name "xml-stylesheet", 'href="mystyle.css" type="text/css"');
74 SELECT xmlpi(name foo, '   bar');
75
76
77 SELECT xmlroot(xml '<foo/>', version no value, standalone no value);
78 SELECT xmlroot(xml '<foo/>', version '2.0');
79 SELECT xmlroot(xml '<foo/>', version no value, standalone yes);
80 SELECT xmlroot(xml '<?xml version="1.1"?><foo/>', version no value, standalone yes);
81 SELECT xmlroot(xmlroot(xml '<foo/>', version '1.0'), version '1.1', standalone no);
82 SELECT xmlroot('<?xml version="1.1" standalone="yes"?><foo/>', version no value, standalone no);
83 SELECT xmlroot('<?xml version="1.1" standalone="yes"?><foo/>', version no value, standalone no value);
84 SELECT xmlroot('<?xml version="1.1" standalone="yes"?><foo/>', version no value);
85
86
87 SELECT xmlroot (
88   xmlelement (
89     name gazonk,
90     xmlattributes (
91       'val' AS name,
92       1 + 1 AS num
93     ),
94     xmlelement (
95       NAME qux,
96       'foo'
97     )
98   ),
99   version '1.0',
100   standalone yes
101 );
102
103
104 SELECT xmlserialize(content data as character varying(20)) FROM xmltest;
105 SELECT xmlserialize(content 'good' as char(10));
106 SELECT xmlserialize(document 'bad' as text);
107
108
109 SELECT xml '<foo>bar</foo>' IS DOCUMENT;
110 SELECT xml '<foo>bar</foo><bar>foo</bar>' IS DOCUMENT;
111 SELECT xml '<abc/>' IS NOT DOCUMENT;
112 SELECT xml 'abc' IS NOT DOCUMENT;
113 SELECT '<>' IS NOT DOCUMENT;
114
115
116 SELECT xmlagg(data) FROM xmltest;
117 SELECT xmlagg(data) FROM xmltest WHERE id > 10;
118 SELECT xmlelement(name employees, xmlagg(xmlelement(name name, name))) FROM emp;
119
120
121 -- Check mapping SQL identifier to XML name
122
123 SELECT xmlpi(name ":::_xml_abc135.%-&_");
124 SELECT xmlpi(name "123");
125
126
127 PREPARE foo (xml) AS SELECT xmlconcat('<foo/>', $1);
128
129 SET XML OPTION DOCUMENT;
130 EXECUTE foo ('<bar/>');
131 EXECUTE foo ('bad');
132
133 SET XML OPTION CONTENT;
134 EXECUTE foo ('<bar/>');
135 EXECUTE foo ('good');
136
137
138 -- Test backwards parsing
139
140 CREATE VIEW xmlview1 AS SELECT xmlcomment('test');
141 CREATE VIEW xmlview2 AS SELECT xmlconcat('hello', 'you');
142 CREATE VIEW xmlview3 AS SELECT xmlelement(name element, xmlattributes (1 as ":one:", 'deuce' as two), 'content&');
143 CREATE VIEW xmlview4 AS SELECT xmlelement(name employee, xmlforest(name, age, salary as pay)) FROM emp;
144 CREATE VIEW xmlview5 AS SELECT xmlparse(content '<abc>x</abc>');
145 CREATE VIEW xmlview6 AS SELECT xmlpi(name foo, 'bar');
146 CREATE VIEW xmlview7 AS SELECT xmlroot(xml '<foo/>', version no value, standalone yes);
147 CREATE VIEW xmlview8 AS SELECT xmlserialize(content 'good' as char(10));
148 CREATE VIEW xmlview9 AS SELECT xmlserialize(content 'good' as text);
149
150 SELECT table_name, view_definition FROM information_schema.views
151   WHERE table_name LIKE 'xmlview%' ORDER BY 1;
152
153 -- Text XPath expressions evaluation
154
155 SELECT xpath('/value', data) FROM xmltest;
156 SELECT xpath(NULL, NULL) IS NULL FROM xmltest;
157 SELECT xpath('', '<!-- error -->');
158 SELECT xpath('//text()', '<local:data xmlns:local="http://127.0.0.1"><local:piece id="1">number one</local:piece><local:piece id="2" /></local:data>');
159 SELECT xpath('//loc:piece/@id', '<local:data xmlns:local="http://127.0.0.1"><local:piece id="1">number one</local:piece><local:piece id="2" /></local:data>', ARRAY[ARRAY['loc', 'http://127.0.0.1']]);
160 SELECT xpath('//b', '<a>one <b>two</b> three <b>etc</b></a>');