Troubleshooting SQL20305N messages issued by INSERT or UPDATE statements
To determine the cause of SQL20305N error messages, refer to "Problem determination for SQL20305N and SQL20306N error messages" in the parent topic, then follow these steps:
Procedure
Example: INSERT statement error
In the
following example, hello world
is an invalid DOUBLE
value, and the entire value is used in the generated XQuery predicate.
Note that *N
is used as a placeholder in the error
message where schema information is not applicable.
CREATE TABLE t1 (x XML);
CREATE INDEX ix1 ON t1(x)
GENERATE KEY USING XMLPATTERN '/root/x/text()'
AS SQL DOUBLE REJECT INVALID VALUES;
DB20000I The SQL command completed successfully.
INSERT INTO t1 VALUES (XMLPARSE (DOCUMENT
'The beginning of the documenthello world'
STRIP WHITESPACE));
DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL20305N An XML value cannot be inserted or updated because of an error
detected when inserting or updating the index identified by "IID = 23" on
table "ADUA.T". Reason code = "5". For reason codes related to an XML schema
the XML schema identifier = "*N" and XML schema data type = "*N".
SQLSTATE=23525
The output in the db2diag log file is as follows (with minor formatting changes):
2007-03-06-12.02.08.116046-480 I4436A1141 LEVEL: Warning
PID : 1544348 TID : 1801 PROC : db2sysc
INSTANCE: adua NODE : 000 DB : ADTEST
APPHDL : 0-18 APPID: *LOCAL.adua.070306200203
AUTHID : ADUA
EDUID : 1801 EDUNAME: db2agent (ADTEST)
FUNCTION: DB2 UDB, Xml Storage and Index Manager,
xmlsIkaProcessErrorMsg, probe:651
MESSAGE : ZRC=0x80A50411=-2136669167=XMS_XML_IX_INSERT_UPDATE_ERROR
"XML node value error during insert or update XML index"
DATA #1 : String, 36 bytes
SQL Code: SQL20305N ; Reason Code: 5
DATA #2 : String, 321 bytes
To locate the value in the document that caused the error, create
a new table with the same columns as the original table and insert
the failing document in the table. Do not create any indexes on
the new table. Replace the table name in the query below with the
newly created table name and execute the following XQuery.
DATA #3 : String, 187 bytes
xquery for $i in db2-fn:xmlcolumn("ADUA.T.X")[/*:root/*:x/text()="hello world"]
return
<Result>
<ProblemDocument> {$i} </ProblemDocument>
<ProblemValue>{$i/*:root/*:x/text()/..} </ProblemValue>
</Result>;
To find the failing node value:
- Create a new table with the same columns as the original table:
CREATE TABLE t2 LIKE t1;
- Insert the failing document into the new table:
INSERT INTO t2 VALUES (XMLPARSE (DOCUMENT 'The beginning of the documenthello world' STRIP WHITESPACE));
- Copy the generated XQuery statement from the db2diag log
file and replace the table name in the XQuery with the new table name:
xquery for $i in db2-fn:xmlcolumn("ADUA.T2.X")[/*:root/*:x/text()="hello world"] return {$i} {$i/*:root/*:x/text()/..} ;
- Execute the XQuery statement against the new table. The result
of the query statement is as follows (with minor formatting changes):
<Result> <ProblemDocument> <root>The beginning of the document<x>hello world</x></root> </ProblemDocument> <ProblemValue><x>hello world</x></ProblemValue> </Result>
Correct the error:
The document can be changed so that the <x> element has a numeric value that will cast successfully to the DOUBLE data type:
INSERT INTO t1 VALUES (
XMLPARSE (DOCUMENT
'<root>The beginning of the document<x>123</x></root>'
STRIP WHITESPACE))