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