Updated on 2025-05-29 GMT+08:00

XMLType

The XMLType data type is used to store XMLType data. Currently, data is stored in character strings. Its advantage over storing XML data in a TEXT field is that, XMLType data supports standard XML operation functions based on LIBXML2 and XML standardization check. For details about functions related to XMLType, see Functions of the XMLType Type.

The XMLType type can store well-formed "documents" that comply with the XML standard.

The XML parser converts an XML document into an XML DOM object. The document object model (DOM) defines standard methods for accessing and manipulating documents. XML DOM defines standard methods for accessing and manipulating XML documents. XML DOM views XML documents as a tree structure. All elements can be accessed through the DOM tree. You can modify or delete their contents and create new elements. An element, the text of the element, and the attributes of the element are all considered as nodes. The maximum size is 1 GB.

Example:

gaussdb=# CREATE TABLE xmltypetest(id int, data xmltype);
gaussdb=# INSERT INTO xmltypetest VALUES (1, '<ss/>');
gaussdb=# INSERT INTO xmltypetest VALUES (2, '<xx/>');
gaussdb=# SELECT * FROM xmltypetest ORDER BY 1;
 id | data
----+-------
  1 | <ss/>
  2 | <xx/>
(2 rows)
gaussdb=# DROP TABLE xmltypetest;
The XMLType type does not support the following operations:
  • Logical expressions AND, OR, and NOT.
  • Input parameter of a system function that is used as a non-XMLType operation function.
  • Used as a distribution key, partition key, level-2 partition key, foreign key, primary key, or unique constraint.
  • Implicit conversion related to XMLType, including the conversion between strings and the XMLType data type.
  • Array expression, row expression, subquery expression, TABLE OF, and TABLE OF INDEX.
  • Column of the XMLType data format that is used as an ordinary index, unique index, global index, local index, or partial index.
  • Comparison expressions >, <, >=, <=, =, <>, !=, ^=, <=>, BETWEEN AND, IS DISTINCT FROM, and IS NOT DISTINCT FROM.
  • Condition expressions DECODE, NULLIF, GREATEST, and LEAST.
  • Used as DISTINCT, GROUP BY, or ORDER BY parameters.
  • Aggregate functions, including sum, max, min, avg, list_agg, corr, covar_pop, covar_samp, stddev, stddev_pop, stddev_samp, var_pop, var_samp, variance, bit_and, bit_or, bool_and, bool_or, every, regr_avgx, regr_avgy, regr_count, regr_intercept, regr_r2, regr_slope, regr_sxx, regr_sxy, regr_syy, rank, and spread.
  • ODBC-related APIs with binding parameters.
The XMLType type supports the following operations:
  • Physical backup and restoration.
  • Comparison expressions IS NULL and IS NOT NULL.
  • Condition expressions CASE and COALESCE.
  • Global temporary tables and local temporary tables.
  • Forcible type conversion.
  • Expression indexes.
  • Input XMLType values that comply with the XML standard.
  • gs_dump and gs_restore.
  • Parallel query, supporting Astore and Ustore.
  • Input parameters, output parameters, customized variables, and return values of a user-defined function.
  • Input parameters, output parameters, customized variables, and return values of a stored procedure, as well as stored procedures that support autonomous transactions.
  • Character processing functions quote_literal(string text) (explicitly converted to the character type) and quote_nullable(string text) (explicitly converted to the character type).
  • Aggregate functions count, array_agg, and checksum (explicitly converted to the character type), and string_agg (explicitly converted to the character type).
  • If addition, deletion, modification, and query of user-defined composite types involve XMLType types that are similar to XMLType columns in ordinary tables, the composite types must be inserted and modified based on the XMLType syntax.
  • You can perform the SELECT, UPDATE, INSERT, or DELETE operation on the column and use the SQL syntax to enter the XMLTYPE value.

You can create a schema named xmltype. In the schema, you can create functions, but cannot use schema.func() to call functions defined in the schema.