Updated on 2024-05-07 GMT+08:00

XMLType

The XMLType data type is used to store XMLType data. Currently, data is stored in character strings in the internal format. Its advantage over storing XML data in a TEXT field is that, XML data supports standard XML operation functions based on LIBXML2 and XML standardization check.

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. Elements, their text, and their attributes are 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 xmltest;
  • 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
    • Use columns of the XMLType data format as common indexes, unique indexes, global indexes, local indexes, and partial indexes.
    • 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 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. The Astore and Ustore storage engines are supported.
    • 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 function 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 common tables, the composite types must be inserted and modified based on the XMLType syntax.
    • The SELECT, UPDATE, INSERT, and DELETE operations can be performed on an XMLType column. You can enter an XMLType value using the SQL syntax.
  • 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.