diff --git a/README.md b/README.md
index 4e7f451bd182f5d1e3efa269e77637736219d118..16d1c9150a0280718343737c134d0199fb9108f2 100644
--- a/README.md
+++ b/README.md
@@ -472,6 +472,7 @@ Compilation log: **make_compile.log**
export PATH=$GAUSSHOME/bin:$GCC_PATH/gcc/bin:$PATH
```
+ if you want to use xml data type,you also need to export LD_LIBRARY_PATH=$BINARYLIBS/dependency/***/libobs/comm/lib:$LD_LIBRARY_PATH
For example, on CENTOS X86-64 platform, binarylibs directory is placed as the sibling directory of openGauss-server directory.
The following command can be executed under openGauss-server directory.
@@ -515,6 +516,7 @@ Compilation log: **make_compile.log**
> 4. If **binarylibs** is moved to **openGauss-server** or a soft link to **binarylibs** is created in **openGauss-server**, you do not need to specify the **--3rd** parameter. However, if you do so, please note that the file is easy to be deleted by the `git clean` command.
> 5. To build with mysql_fdw, add **--enable-mysql-fdw** when configure. Note that before build mysql_fdw, MariaDB's C client library is needed.
> 6. To build with oracle_fdw, add **--enable-oracle-fdw** when configure. Note that before build oracle_fdw, Oracle's C client library is needed.
+ > 7. To build with xml data type, add **--with-libxml** when configure. If this error occurs "configure: error: library 'xml2' (version >= 2.6.23) is required for XML support", you can fix it with command "yum install -y libxml2-devel".
4. Run the following commands to compile openGauss:
diff --git a/src/common/backend/parser/parse_type.cpp b/src/common/backend/parser/parse_type.cpp
index 2c26a5c4b126378be486f5c216b0ecec617fcd4d..a74549d40de94fd8e16e4c8dbb2a800d1405fa40 100755
--- a/src/common/backend/parser/parse_type.cpp
+++ b/src/common/backend/parser/parse_type.cpp
@@ -826,7 +826,7 @@ bool IsTypeInBlacklist(Oid typoid)
switch (typoid) {
case LINEOID:
- case XMLOID:
+ // case XMLOID:
case PGNODETREEOID:
isblack = true;
break;
diff --git a/src/common/backend/utils/adt/xml.cpp b/src/common/backend/utils/adt/xml.cpp
index 44fcca4eb4b22a5782704eca5b1bb79cc50045d9..c398840a9d6636bb13a08c7a4a94134f9b4dcd11 100755
--- a/src/common/backend/utils/adt/xml.cpp
+++ b/src/common/backend/utils/adt/xml.cpp
@@ -1421,12 +1421,12 @@ void xml_ereport(PgXmlErrorContext* errcxt, int level, int sqlcode, const char*
/*
* Error handler for libxml errors and warnings
*/
-static void xml_errorHandler(void* data, xmlErrorPtr error)
+static void xml_error_handler(void* data, xmlErrorPtr error)
{
PgXmlErrorContext* xml_errcxt = (PgXmlErrorContext*)data;
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr)error->ctxt;
xmlParserInputPtr input = (ctxt != NULL) ? ctxt->input : NULL;
- xmlNodePtr node = error->node;
+ xmlNodePtr node = (xmlNodePtr)error->node;
const xmlChar* name = (node != NULL && node->type == XML_ELEMENT_NODE) ? node->name : NULL;
int domain = error->domain;
int level = error->level;
@@ -1915,7 +1915,7 @@ char* map_sql_value_to_xml_value(Datum value, Oid type, bool xml_escape_strings)
if (writer == NULL || xml_errcxt->err_occurred) {
xml_ereport(xml_errcxt, ERROR, ERRCODE_OUT_OF_MEMORY, "could not allocate xmlTextWriter");
}
- if (xmlbinary == XMLBINARY_BASE64) {
+ if (u_sess->attr.attr_common.xmlbinary == XMLBINARY_BASE64) {
xmlTextWriterWriteBase64(writer, VARDATA_ANY(b_str), 0, VARSIZE_ANY_EXHDR(b_str));
} else {
xmlTextWriterWriteBinHex(writer, VARDATA_ANY(b_str), 0, VARSIZE_ANY_EXHDR(b_str));
diff --git a/src/test/regress/expected/single_node_xml.out b/src/test/regress/expected/single_node_xml.out
index d06e3d98c4b085ee89f6f30dfe906f9129a10841..31cb6296d0580f2d75ba6404bf3d73ec5faeca31 100644
--- a/src/test/regress/expected/single_node_xml.out
+++ b/src/test/regress/expected/single_node_xml.out
@@ -1,3 +1,4 @@
+\set VERBOSITY terse
CREATE TABLE xmltest (
id int,
data xml
@@ -5,12 +6,7 @@ CREATE TABLE xmltest (
INSERT INTO xmltest VALUES (1, 'one');
INSERT INTO xmltest VALUES (2, 'two');
INSERT INTO xmltest VALUES (3, '', NULL, '');
xmlconcat
--------------
@@ -99,16 +88,21 @@ SELECT xmlelement(name element,
SELECT xmlelement(name element,
xmlattributes ('unnamed and wrong'));
-ERROR: unnamed XML attribute value must be a column reference
-LINE 2: xmlattributes ('unnamed and wrong'));
- ^
+ERROR: unnamed XML attribute value must be a column reference at character 66
SELECT xmlelement(name element, xmlelement(name nested, 'stuff'));
xmlelement
-------------------------------------------
stuff
(1 row)
-SELECT xmlelement(name employee, xmlforest(name, age, salary as pay)) FROM emp;
+CREATE TABLE xml_emp (name varchar(12),age int,salary int);
+INSERT INTO xml_emp VALUES ('sharon',25,1000);
+INSERT INTO xml_emp VALUES ('sam',30,2000);
+INSERT INTO xml_emp VALUES ('bill',20,1000);
+INSERT INTO xml_emp VALUES ('jeff',23,600);
+INSERT INTO xml_emp VALUES ('cim',30,400);
+INSERT INTO xml_emp VALUES ('linda',19,100);
+SELECT xmlelement(name employee, xmlforest(name, age, salary as pay)) FROM xml_emp;
xmlelement
----------------------------------------------------------------------
sharon251000
@@ -120,9 +114,7 @@ SELECT xmlelement(name employee, xmlforest(name, age, salary as pay)) FROM emp;
(6 rows)
SELECT xmlelement(name duplicate, xmlattributes(1 as a, 2 as b, 3 as a));
-ERROR: XML attribute name "a" appears more than once
-LINE 1: ...ment(name duplicate, xmlattributes(1 as a, 2 as b, 3 as a));
- ^
+ERROR: XML attribute name "a" appears more than once at character 65
SELECT xmlelement(name num, 37);
xmlelement
---------------
@@ -186,8 +178,7 @@ SELECT xmlelement(name foo, xmlattributes('2009-04-09 00:24:37'::timestamp as ba
(1 row)
SELECT xmlelement(name foo, xmlattributes('infinity'::timestamp as bar));
-ERROR: timestamp out of range
-DETAIL: XML does not support infinite timestamp values.
+ERROR: time_stamp out of range
SELECT xmlelement(name foo, xmlattributes('<>&"''' as funny, xml 'br' as funnier));
xmlelement
------------------------------------------------------------
@@ -208,20 +199,8 @@ SELECT xmlparse(content 'x');
SELECT xmlparse(content '&');
ERROR: invalid XML content
-DETAIL: line 1: xmlParseEntityRef: no name
-&
- ^
-line 1: chunk is not well balanced
-&
- ^
SELECT xmlparse(content '&idontexist;');
ERROR: invalid XML content
-DETAIL: line 1: Entity 'idontexist' not defined
-&idontexist;
- ^
-line 1: chunk is not well balanced
-&idontexist;
- ^
SELECT xmlparse(content '');
xmlparse
---------------------------
@@ -236,15 +215,6 @@ SELECT xmlparse(content '');
SELECT xmlparse(content '&idontexist;');
ERROR: invalid XML content
-DETAIL: line 1: Entity 'idontexist' not defined
-&idontexist;
- ^
-line 1: Opening and ending tag mismatch: twoerrors line 1 and unbalanced
-&idontexist;
- ^
-line 1: chunk is not well balanced
-&idontexist;
- ^
SELECT xmlparse(content '');
xmlparse
---------------------
@@ -253,9 +223,6 @@ SELECT xmlparse(content '');
SELECT xmlparse(document 'abc');
ERROR: invalid XML document
-DETAIL: line 1: Start tag expected, '<' not found
-abc
-^
SELECT xmlparse(document 'x');
xmlparse
--------------
@@ -264,20 +231,8 @@ SELECT xmlparse(document 'x');
SELECT xmlparse(document '&');
ERROR: invalid XML document
-DETAIL: line 1: xmlParseEntityRef: no name
-&
- ^
-line 1: Opening and ending tag mismatch: invalidentity line 1 and abc
-&
- ^
SELECT xmlparse(document '&idontexist;');
ERROR: invalid XML document
-DETAIL: line 1: Entity 'idontexist' not defined
-&idontexist;
- ^
-line 1: Opening and ending tag mismatch: undefinedentity line 1 and abc
-&idontexist;
- ^
SELECT xmlparse(document '');
xmlparse
---------------------------
@@ -292,12 +247,6 @@ SELECT xmlparse(document '');
SELECT xmlparse(document '&idontexist;');
ERROR: invalid XML document
-DETAIL: line 1: Entity 'idontexist' not defined
-&idontexist;
- ^
-line 1: Opening and ending tag mismatch: twoerrors line 1 and unbalanced
-&idontexist;
- ^
SELECT xmlparse(document '');
xmlparse
---------------------
@@ -312,7 +261,6 @@ SELECT xmlpi(name foo);
SELECT xmlpi(name xml);
ERROR: invalid XML processing instruction
-DETAIL: XML processing instruction target name cannot be "xml".
SELECT xmlpi(name xmlstuff);
xmlpi
--------------
@@ -327,7 +275,6 @@ SELECT xmlpi(name foo, 'bar');
SELECT xmlpi(name foo, 'in?>valid');
ERROR: invalid XML processing instruction
-DETAIL: XML processing instruction cannot contain "?>".
SELECT xmlpi(name foo, null);
xmlpi
-------
@@ -336,7 +283,6 @@ SELECT xmlpi(name foo, null);
SELECT xmlpi(name xml, null);
ERROR: invalid XML processing instruction
-DETAIL: XML processing instruction target name cannot be "xml".
SELECT xmlpi(name xmlstuff, null);
xmlpi
-------
@@ -463,12 +409,7 @@ SELECT xml 'abc' IS NOT DOCUMENT;
(1 row)
SELECT '<>' IS NOT DOCUMENT;
-ERROR: invalid XML content
-LINE 1: SELECT '<>' IS NOT DOCUMENT;
- ^
-DETAIL: line 1: StartTag: invalid element name
-<>
- ^
+ERROR: invalid XML content at character 8
SELECT xmlagg(data) FROM xmltest;
xmlagg
--------------------------------------
@@ -481,7 +422,7 @@ SELECT xmlagg(data) FROM xmltest WHERE id > 10;
(1 row)
-SELECT xmlelement(name employees, xmlagg(xmlelement(name name, name))) FROM emp;
+SELECT xmlelement(name employees, xmlagg(xmlelement(name name, name))) FROM xml_emp;
xmlelement
--------------------------------------------------------------------------------------------------------------------------------
sharonsambilljeffcimlinda
@@ -509,12 +450,7 @@ EXECUTE foo ('');
(1 row)
EXECUTE foo ('bad');
-ERROR: invalid XML document
-LINE 1: EXECUTE foo ('bad');
- ^
-DETAIL: line 1: Start tag expected, '<' not found
-bad
-^
+ERROR: invalid XML document at character 14
SET XML OPTION CONTENT;
EXECUTE foo ('');
xmlconcat
@@ -532,7 +468,7 @@ EXECUTE foo ('good');
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 xmlview4 AS SELECT xmlelement(name employee, xmlforest(name, age, salary as pay)) FROM xml_emp;
CREATE VIEW xmlview5 AS SELECT xmlparse(content 'x');
CREATE VIEW xmlview6 AS SELECT xmlpi(name foo, 'bar');
CREATE VIEW xmlview7 AS SELECT xmlroot(xml '', version no value, standalone yes);
@@ -541,11 +477,11 @@ CREATE VIEW xmlview9 AS SELECT xmlserialize(content 'good' as text);
SELECT table_name, view_definition FROM information_schema.views
WHERE table_name LIKE 'xmlview%' ORDER BY 1;
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;
+ xmlview4 | SELECT XMLELEMENT(NAME employee, XMLFOREST(xml_emp.name AS name, xml_emp.age AS age, xml_emp.salary AS pay)) AS "xmlelement" FROM xml_emp;
xmlview5 | SELECT XMLPARSE(CONTENT 'x'::text STRIP WHITESPACE) AS "xmlparse";
xmlview6 | SELECT XMLPI(NAME foo, 'bar'::text) AS "xmlpi";
xmlview7 | SELECT XMLROOT(''::xml, VERSION NO VALUE, STANDALONE YES) AS "xmlroot";
@@ -568,9 +504,8 @@ SELECT xpath(NULL, NULL) IS NULL FROM xmltest;
t
(2 rows)
-SELECT xpath('', '');
-ERROR: empty XPath expression
-CONTEXT: SQL function "xpath" statement 1
+SELECT xpath(' ', '');
+ERROR: could not parse XML document
SELECT xpath('//text()', 'number one');
xpath
----------------
@@ -583,21 +518,6 @@ SELECT xpath('//loc:piece/@id', 'number one', ARRAY[ARRAY['loc', 'http://127.0.0.1']]);
- xpath
-------------------------------------------------------------------------------------------------------------------------------------------------
- {"number one",""}
-(1 row)
-
-SELECT xpath('//loc:piece', 'number one', ARRAY[ARRAY['loc', 'http://127.0.0.1']]);
- xpath
---------------------------------------------------------------------------------------
- {"+
- number one +
- +
- ",""}
-(1 row)
-
SELECT xpath('//b', 'one two three etc');
xpath
-------------------------
@@ -898,14 +818,18 @@ ERROR: could not parse XML document
DETAIL: line 1: Namespace prefix nosuchprefix on tag is not defined
^
-CONTEXT: SQL function "xpath" statement 1
+CONTEXT: referenced column: xpath
+SQL function "xpath" statement 1
+referenced column: xpath
-- XPath deprecates relative namespaces, but they're not supposed to
-- throw an error, only a warning.
SELECT xpath('/*', '');
WARNING: line 1: xmlns: URI relative is not absolute
^
-CONTEXT: SQL function "xpath" statement 1
+CONTEXT: referenced column: xpath
+SQL function "xpath" statement 1
+referenced column: xpath
xpath
--------------------------------------
{""}
diff --git a/src/test/regress/sql/single_node_xml.sql b/src/test/regress/sql/single_node_xml.sql
index ce87d426842f6a1e91a014b43c9c671cc02e5843..3f76546ee02e02df6e41d82409e111172ccbef03 100644
--- a/src/test/regress/sql/single_node_xml.sql
+++ b/src/test/regress/sql/single_node_xml.sql
@@ -1,3 +1,4 @@
+\set VERBOSITY terse
CREATE TABLE xmltest (
id int,
data xml
@@ -38,8 +39,15 @@ SELECT xmlelement(name element,
xmlattributes ('unnamed and wrong'));
SELECT xmlelement(name element, xmlelement(name nested, 'stuff'));
+CREATE TABLE xml_emp (name varchar(12),age int,salary int);
+INSERT INTO xml_emp VALUES ('sharon',25,1000);
+INSERT INTO xml_emp VALUES ('sam',30,2000);
+INSERT INTO xml_emp VALUES ('bill',20,1000);
+INSERT INTO xml_emp VALUES ('jeff',23,600);
+INSERT INTO xml_emp VALUES ('cim',30,400);
+INSERT INTO xml_emp VALUES ('linda',19,100);
-SELECT xmlelement(name employee, xmlforest(name, age, salary as pay)) FROM emp;
+SELECT xmlelement(name employee, xmlforest(name, age, salary as pay)) FROM xml_emp;
SELECT xmlelement(name duplicate, xmlattributes(1 as a, 2 as b, 3 as a));
@@ -132,7 +140,7 @@ SELECT '<>' IS NOT DOCUMENT;
SELECT xmlagg(data) FROM xmltest;
SELECT xmlagg(data) FROM xmltest WHERE id > 10;
-SELECT xmlelement(name employees, xmlagg(xmlelement(name name, name))) FROM emp;
+SELECT xmlelement(name employees, xmlagg(xmlelement(name name, name))) FROM xml_emp;
-- Check mapping SQL identifier to XML name
@@ -157,7 +165,7 @@ EXECUTE foo ('good');
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 xmlview4 AS SELECT xmlelement(name employee, xmlforest(name, age, salary as pay)) FROM xml_emp;
CREATE VIEW xmlview5 AS SELECT xmlparse(content 'x');
CREATE VIEW xmlview6 AS SELECT xmlpi(name foo, 'bar');
CREATE VIEW xmlview7 AS SELECT xmlroot(xml '', version no value, standalone yes);
@@ -171,11 +179,9 @@ SELECT table_name, view_definition FROM information_schema.views
SELECT xpath('/value', data) FROM xmltest;
SELECT xpath(NULL, NULL) IS NULL FROM xmltest;
-SELECT xpath('', '');
+SELECT xpath(' ', '');
SELECT xpath('//text()', 'number one');
SELECT xpath('//loc:piece/@id', 'number one', ARRAY[ARRAY['loc', 'http://127.0.0.1']]);
-SELECT xpath('//loc:piece', 'number one', ARRAY[ARRAY['loc', 'http://127.0.0.1']]);
-SELECT xpath('//loc:piece', 'number one', ARRAY[ARRAY['loc', 'http://127.0.0.1']]);
SELECT xpath('//b', 'one two three etc');
SELECT xpath('//text()', '<');
SELECT xpath('//@value', '');