]> granicus.if.org Git - postgresql/blob - contrib/xml2/sql/xml2.sql
Fix up memory management problems in contrib/xml2.
[postgresql] / contrib / xml2 / sql / xml2.sql
1 --
2 -- first, define the functions.  Turn off echoing so that expected file
3 -- does not depend on contents of pgxml.sql.
4 --
5 SET client_min_messages = warning;
6 \set ECHO none
7 \i pgxml.sql
8 \set ECHO all
9 RESET client_min_messages;
10
11 select query_to_xml('select 1 as x',true,false,'');
12
13 select xslt_process( query_to_xml('select x from generate_series(1,5) as 
14 x',true,false,'')::text,
15 $$<xsl:stylesheet version="1.0"
16                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
17 <xsl:output method="xml" indent="yes" />
18 <xsl:template match="*">
19   <xsl:copy>
20      <xsl:copy-of select="@*" />
21      <xsl:apply-templates />
22   </xsl:copy>
23 </xsl:template>
24 <xsl:template match="comment()|processing-instruction()">
25   <xsl:copy />
26 </xsl:template>
27 </xsl:stylesheet>
28 $$::text);
29
30 CREATE TABLE xpath_test (id integer NOT NULL, t xml);
31 INSERT INTO xpath_test VALUES (1, '<doc><int>1</int></doc>');
32 SELECT * FROM xpath_table('id', 't', 'xpath_test', '/doc/int', 'true')
33 as t(id int4);
34 SELECT * FROM xpath_table('id', 't', 'xpath_test', '/doc/int', 'true')
35 as t(id int4, doc int4);
36
37 DROP TABLE xpath_test;
38 CREATE TABLE xpath_test (id integer NOT NULL, t text);
39 INSERT INTO xpath_test VALUES (1, '<doc><int>1</int></doc>');
40 SELECT * FROM xpath_table('id', 't', 'xpath_test', '/doc/int', 'true')
41 as t(id int4);
42 SELECT * FROM xpath_table('id', 't', 'xpath_test', '/doc/int', 'true')
43 as t(id int4, doc int4);
44
45 create table articles (article_id integer, article_xml xml, date_entered date);
46 insert into articles (article_id, article_xml, date_entered)
47 values (2, '<article><author>test</author><pages>37</pages></article>', now());
48 SELECT * FROM
49 xpath_table('article_id',
50             'article_xml',
51             'articles',
52             '/article/author|/article/pages|/article/title',
53             'date_entered > ''2003-01-01'' ')
54 AS t(article_id integer, author text, page_count integer, title text);
55
56 -- this used to fail when invoked a second time
57 select xslt_process('<aaa/>',$$<xsl:stylesheet version="1.0"
58 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
59 <xsl:template match="@*|node()">
60       <xsl:copy>
61          <xsl:apply-templates select="@*|node()"/>
62       </xsl:copy>
63    </xsl:template>
64 </xsl:stylesheet>$$)::xml;
65
66 select xslt_process('<aaa/>',$$<xsl:stylesheet version="1.0"
67 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
68 <xsl:template match="@*|node()">
69       <xsl:copy>
70          <xsl:apply-templates select="@*|node()"/>
71       </xsl:copy>
72    </xsl:template>
73 </xsl:stylesheet>$$)::xml;
74
75 create table t1 (id integer, xml_data xml);
76 insert into t1 (id, xml_data)
77 values
78 (1, '<attributes><attribute name="attr_1">Some
79 Value</attribute></attributes>');
80
81 create index idx_xpath on t1 ( xpath_string
82 ('/attributes/attribute[@name="attr_1"]/text()', xml_data::text));