]> granicus.if.org Git - postgresql/blob - src/test/regress/expected/xml.out
8ffde1dc6af7c9b912a659b1064b300f51551866
[postgresql] / src / test / regress / expected / xml.out
1 CREATE TABLE xmltest (
2     id int,
3     data xml
4 );
5 INSERT INTO xmltest VALUES (1, '<value>one</value>');
6 INSERT INTO xmltest VALUES (2, '<value>two</value>');
7 INSERT INTO xmltest VALUES (3, '<wrong');
8 ERROR:  invalid XML content
9 DETAIL:  Entity: line 1: parser error : Couldn't find end of Start Tag wrong line 1
10 <wrong
11       ^
12 SELECT * FROM xmltest;
13  id |        data        
14 ----+--------------------
15   1 | <value>one</value>
16   2 | <value>two</value>
17 (2 rows)
18
19 SELECT xmlcomment('test');
20  xmlcomment  
21 -------------
22  <!--test-->
23 (1 row)
24
25 SELECT xmlcomment('-test');
26   xmlcomment  
27 --------------
28  <!---test-->
29 (1 row)
30
31 SELECT xmlcomment('test-');
32 ERROR:  invalid XML comment
33 SELECT xmlcomment('--test');
34 ERROR:  invalid XML comment
35 SELECT xmlcomment('te st');
36   xmlcomment  
37 --------------
38  <!--te st-->
39 (1 row)
40
41 SELECT xmlconcat(xmlcomment('hello'),
42                  xmlelement(NAME qux, 'foo'),
43                  xmlcomment('world'));
44                xmlconcat                
45 ----------------------------------------
46  <!--hello--><qux>foo</qux><!--world-->
47 (1 row)
48
49 SELECT xmlconcat('hello', 'you');
50  xmlconcat 
51 -----------
52  helloyou
53 (1 row)
54
55 SELECT xmlconcat(1, 2);
56 ERROR:  argument of XMLCONCAT must be type xml, not type integer
57 SELECT xmlconcat('bad', '<syntax');
58 ERROR:  invalid XML content
59 DETAIL:  Entity: line 1: parser error : Couldn't find end of Start Tag syntax line 1
60 <syntax
61        ^
62 SELECT xmlconcat('<foo/>', NULL, '<?xml version="1.1" standalone="no"?><bar/>');
63   xmlconcat   
64 --------------
65  <foo/><bar/>
66 (1 row)
67
68 SELECT xmlconcat('<?xml version="1.1"?><foo/>', NULL, '<?xml version="1.1" standalone="no"?><bar/>');
69              xmlconcat             
70 -----------------------------------
71  <?xml version="1.1"?><foo/><bar/>
72 (1 row)
73
74 SELECT xmlelement(name element,
75                   xmlattributes (1 as one, 'deuce' as two),
76                   'content');
77                    xmlelement                   
78 ------------------------------------------------
79  <element one="1" two="deuce">content</element>
80 (1 row)
81
82 SELECT xmlelement(name element,
83                   xmlattributes ('unnamed and wrong'));
84 ERROR:  unnamed XML attribute value must be a column reference
85 SELECT xmlelement(name element, xmlelement(name nested, 'stuff'));
86                 xmlelement                 
87 -------------------------------------------
88  <element><nested>stuff</nested></element>
89 (1 row)
90
91 SELECT xmlelement(name employee, xmlforest(name, age, salary as pay)) FROM emp;
92                               xmlelement                              
93 ----------------------------------------------------------------------
94  <employee><name>sharon</name><age>25</age><pay>1000</pay></employee>
95  <employee><name>sam</name><age>30</age><pay>2000</pay></employee>
96  <employee><name>bill</name><age>20</age><pay>1000</pay></employee>
97  <employee><name>jeff</name><age>23</age><pay>600</pay></employee>
98  <employee><name>cim</name><age>30</age><pay>400</pay></employee>
99  <employee><name>linda</name><age>19</age><pay>100</pay></employee>
100 (6 rows)
101
102 SELECT xmlelement(name duplicate, xmlattributes(1 as a, 2 as b, 3 as a));
103 ERROR:  XML attribute name "a" appears more than once
104 SELECT xmlelement(name num, 37);
105   xmlelement   
106 ---------------
107  <num>37</num>
108 (1 row)
109
110 SELECT xmlelement(name foo, text 'bar');
111    xmlelement   
112 ----------------
113  <foo>bar</foo>
114 (1 row)
115
116 SELECT xmlelement(name foo, xml 'bar');
117    xmlelement   
118 ----------------
119  <foo>bar</foo>
120 (1 row)
121
122 SELECT xmlelement(name foo, text 'b<a/>r');
123        xmlelement        
124 -------------------------
125  <foo>b&lt;a/&gt;r</foo>
126 (1 row)
127
128 SELECT xmlelement(name foo, xml 'b<a/>r');
129     xmlelement     
130 -------------------
131  <foo>b<a/>r</foo>
132 (1 row)
133
134 SELECT xmlelement(name foo, array[1, 2, 3]);
135                                xmlelement                                
136 -------------------------------------------------------------------------
137  <foo><element>1</element><element>2</element><element>3</element></foo>
138 (1 row)
139
140 SET xmlbinary TO base64;
141 SELECT xmlelement(name foo, bytea 'bar');
142    xmlelement    
143 -----------------
144  <foo>YmFy</foo>
145 (1 row)
146
147 SET xmlbinary TO hex;
148 SELECT xmlelement(name foo, bytea 'bar');
149     xmlelement     
150 -------------------
151  <foo>626172</foo>
152 (1 row)
153
154 SELECT xmlparse(content 'abc');
155  xmlparse 
156 ----------
157  abc
158 (1 row)
159
160 SELECT xmlparse(content '<abc>x</abc>');
161    xmlparse   
162 --------------
163  <abc>x</abc>
164 (1 row)
165
166 SELECT xmlparse(document 'abc');
167 ERROR:  invalid XML document
168 DETAIL:  Entity: line 1: parser error : Start tag expected, '<' not found
169 abc
170 ^
171 SELECT xmlparse(document '<abc>x</abc>');
172    xmlparse   
173 --------------
174  <abc>x</abc>
175 (1 row)
176
177 SELECT xmlpi(name foo);
178   xmlpi  
179 ---------
180  <?foo?>
181 (1 row)
182
183 SELECT xmlpi(name xmlstuff);
184 ERROR:  invalid XML processing instruction
185 DETAIL:  XML processing instruction target name cannot start with "xml".
186 SELECT xmlpi(name foo, 'bar');
187     xmlpi    
188 -------------
189  <?foo bar?>
190 (1 row)
191
192 SELECT xmlpi(name foo, 'in?>valid');
193 ERROR:  invalid XML processing instruction
194 DETAIL:  XML processing instruction cannot contain "?>".
195 SELECT xmlpi(name foo, null);
196  xmlpi 
197 -------
198  
199 (1 row)
200
201 SELECT xmlpi(name xmlstuff, null);
202 ERROR:  invalid XML processing instruction
203 DETAIL:  XML processing instruction target name cannot start with "xml".
204 SELECT xmlpi(name foo, '   bar');
205     xmlpi    
206 -------------
207  <?foo bar?>
208 (1 row)
209
210 SELECT xmlroot(xml '<foo/>', version no value, standalone no value);
211  xmlroot 
212 ---------
213  <foo/>
214 (1 row)
215
216 SELECT xmlroot(xml '<foo/>', version '2.0');
217            xmlroot           
218 -----------------------------
219  <?xml version="2.0"?><foo/>
220 (1 row)
221
222 SELECT xmlroot(xml '<foo/>', version no value, standalone yes);
223                    xmlroot                    
224 ----------------------------------------------
225  <?xml version="1.0" standalone="yes"?><foo/>
226 (1 row)
227
228 SELECT xmlroot(xml '<?xml version="1.1"?><foo/>', version no value, standalone yes);
229                    xmlroot                    
230 ----------------------------------------------
231  <?xml version="1.0" standalone="yes"?><foo/>
232 (1 row)
233
234 SELECT xmlroot(xmlroot(xml '<foo/>', version '1.0'), version '1.1', standalone no);
235                    xmlroot                   
236 ---------------------------------------------
237  <?xml version="1.1" standalone="no"?><foo/>
238 (1 row)
239
240 SELECT xmlroot('<?xml version="1.1" standalone="yes"?><foo/>', version no value, standalone no);
241                    xmlroot                   
242 ---------------------------------------------
243  <?xml version="1.0" standalone="no"?><foo/>
244 (1 row)
245
246 SELECT xmlroot('<?xml version="1.1" standalone="yes"?><foo/>', version no value, standalone no value);
247  xmlroot 
248 ---------
249  <foo/>
250 (1 row)
251
252 SELECT xmlroot('<?xml version="1.1" standalone="yes"?><foo/>', version no value);
253                    xmlroot                    
254 ----------------------------------------------
255  <?xml version="1.0" standalone="yes"?><foo/>
256 (1 row)
257
258 SELECT xmlroot (
259   xmlelement (
260     name gazonk,
261     xmlattributes (
262       'val' AS name,
263       1 + 1 AS num
264     ),
265     xmlelement (
266       NAME qux,
267       'foo'
268     )
269   ),
270   version '1.0',
271   standalone yes
272 );
273                                          xmlroot                                          
274 ------------------------------------------------------------------------------------------
275  <?xml version="1.0" standalone="yes"?><gazonk name="val" num="2"><qux>foo</qux></gazonk>
276 (1 row)
277
278 SELECT xmlserialize(content data as character varying(20)) FROM xmltest;
279     xmlserialize    
280 --------------------
281  <value>one</value>
282  <value>two</value>
283 (2 rows)
284
285 SELECT xmlserialize(content 'good' as char(10));
286  xmlserialize 
287 --------------
288  good      
289 (1 row)
290
291 SELECT xmlserialize(document 'bad' as text);
292 ERROR:  not an XML document
293 SELECT xml '<foo>bar</foo>' IS DOCUMENT;
294  ?column? 
295 ----------
296  t
297 (1 row)
298
299 SELECT xml '<foo>bar</foo><bar>foo</bar>' IS DOCUMENT;
300  ?column? 
301 ----------
302  f
303 (1 row)
304
305 SELECT xml '<abc/>' IS NOT DOCUMENT;
306  ?column? 
307 ----------
308  f
309 (1 row)
310
311 SELECT xml 'abc' IS NOT DOCUMENT;
312  ?column? 
313 ----------
314  t
315 (1 row)
316
317 SELECT '<>' IS NOT DOCUMENT;
318 ERROR:  invalid XML content
319 DETAIL:  Entity: line 1: parser error : StartTag: invalid element name
320 <>
321  ^
322 SELECT xmlagg(data) FROM xmltest;
323                 xmlagg                
324 --------------------------------------
325  <value>one</value><value>two</value>
326 (1 row)
327
328 SELECT xmlagg(data) FROM xmltest WHERE id > 10;
329  xmlagg 
330 --------
331  
332 (1 row)
333
334 SELECT xmlelement(name employees, xmlagg(xmlelement(name name, name))) FROM emp;
335                                                            xmlelement                                                           
336 --------------------------------------------------------------------------------------------------------------------------------
337  <employees><name>sharon</name><name>sam</name><name>bill</name><name>jeff</name><name>cim</name><name>linda</name></employees>
338 (1 row)
339
340 -- Check mapping SQL identifier to XML name
341 SELECT xmlpi(name ":::_xml_abc135.%-&_");
342                       xmlpi                      
343 -------------------------------------------------
344  <?_x003A_::_x005F_xml_abc135._x0025_-_x0026__?>
345 (1 row)
346
347 SELECT xmlpi(name "123");
348      xmlpi     
349 ---------------
350  <?_x0031_23?>
351 (1 row)
352
353 PREPARE foo (xml) AS SELECT xmlconcat('<foo/>', $1);
354 SET XML OPTION DOCUMENT;
355 EXECUTE foo ('<bar/>');
356   xmlconcat   
357 --------------
358  <foo/><bar/>
359 (1 row)
360
361 EXECUTE foo ('bad');
362 ERROR:  invalid XML document
363 DETAIL:  Entity: line 1: parser error : Start tag expected, '<' not found
364 bad
365 ^
366 SET XML OPTION CONTENT;
367 EXECUTE foo ('<bar/>');
368   xmlconcat   
369 --------------
370  <foo/><bar/>
371 (1 row)
372
373 EXECUTE foo ('good');
374  xmlconcat  
375 ------------
376  <foo/>good
377 (1 row)
378
379 -- Test backwards parsing
380 CREATE VIEW xmlview1 AS SELECT xmlcomment('test');
381 CREATE VIEW xmlview2 AS SELECT xmlconcat('hello', 'you');
382 CREATE VIEW xmlview3 AS SELECT xmlelement(name element, xmlattributes (1 as ":one:", 'deuce' as two), 'content&');
383 CREATE VIEW xmlview4 AS SELECT xmlelement(name employee, xmlforest(name, age, salary as pay)) FROM emp;
384 CREATE VIEW xmlview5 AS SELECT xmlparse(content '<abc>x</abc>');
385 CREATE VIEW xmlview6 AS SELECT xmlpi(name foo, 'bar');
386 CREATE VIEW xmlview7 AS SELECT xmlroot(xml '<foo/>', version no value, standalone yes);
387 CREATE VIEW xmlview8 AS SELECT xmlserialize(content 'good' as char(10));
388 CREATE VIEW xmlview9 AS SELECT xmlserialize(content 'good' as text);
389 SELECT table_name, view_definition FROM information_schema.views
390   WHERE table_name LIKE 'xmlview%' ORDER BY 1;
391  table_name |                                                      view_definition                                                       
392 ------------+----------------------------------------------------------------------------------------------------------------------------
393  xmlview1   | SELECT xmlcomment('test'::text) AS xmlcomment;
394  xmlview2   | SELECT XMLCONCAT('hello'::xml, 'you'::xml) AS "xmlconcat";
395  xmlview3   | SELECT XMLELEMENT(NAME element, XMLATTRIBUTES(1 AS ":one:", 'deuce' AS two), 'content&') AS "xmlelement";
396  xmlview4   | SELECT XMLELEMENT(NAME employee, XMLFOREST(emp.name AS name, emp.age AS age, emp.salary AS pay)) AS "xmlelement" FROM emp;
397  xmlview5   | SELECT XMLPARSE(CONTENT '<abc>x</abc>'::text STRIP WHITESPACE) AS "xmlparse";
398  xmlview6   | SELECT XMLPI(NAME foo, 'bar'::text) AS "xmlpi";
399  xmlview7   | SELECT XMLROOT('<foo/>'::xml, VERSION NO VALUE, STANDALONE YES) AS "xmlroot";
400  xmlview8   | SELECT (XMLSERIALIZE(CONTENT 'good'::xml AS character(10)))::character(10) AS "xmlserialize";
401  xmlview9   | SELECT XMLSERIALIZE(CONTENT 'good'::xml AS text) AS "xmlserialize";
402 (9 rows)
403
404 -- Text XPath expressions evaluation
405 SELECT xpath('/value', data) FROM xmltest;
406         xpath         
407 ----------------------
408  {<value>one</value>}
409  {<value>two</value>}
410 (2 rows)
411
412 SELECT xpath(NULL, NULL) IS NULL FROM xmltest;
413  ?column? 
414 ----------
415  t
416  t
417 (2 rows)
418
419 SELECT xpath('', '<!-- error -->');
420 ERROR:  empty XPath expression
421 CONTEXT:  SQL function "xpath" statement 1
422 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>');
423      xpath      
424 ----------------
425  {"number one"}
426 (1 row)
427
428 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']]);
429  xpath 
430 -------
431  {1,2}
432 (1 row)
433
434 SELECT xpath('//b', '<a>one <b>two</b> three <b>etc</b></a>');
435           xpath          
436 -------------------------
437  {<b>two</b>,<b>etc</b>}
438 (1 row)
439