I ran into a problem running a simple test xquery. I hadn’t directly dealt with XML namespaces in xquery prior to this, but the documentation was clear enough:
XQUERY
declare default element namespace "http://posample.org"
for $x in db2-fn:xmlcolumn("PURCHASEORDER.PORDER")
return $x
Oops, EOF error. It needs a terminator.
XQUERY
declare default element namespace "http://posample.org"
for $x in db2-fn:xmlcolumn("PURCHASEORDER.PORDER")
return $x;
Unexpected “for” following the namespace declaration? Pardon? It turns out xquery prologs need to be terminated by a semicolon:
XQUERY
declare default element namespace "http://posample.org";
for $x in db2-fn:xmlcolumn("PURCHASEORDER.PORDER")
return $x;
Unexpected “http://posample.org”? But that’s the exact syntax given in the examples! Alas, this semicolon is distinct from the usual semicolon separator in SQL. It’s part of a single xquery statement, so what I need to do is change the SQL separator to something more exotic. This will allow xquery to be parsed correctly:
XQUERY
declare default element namespace "http://posample.org";
for $x in db2-fn:xmlcolumn("PURCHASEORDER.PORDER")
return $x@
Eureka.:)
Ouch… I have tons of fun running SQL queries through ODBC from python. Backwards I know, but it’s the easiest way for me (not officially a programmer) to access the db-2 files on our AS400s. I hit these weird limitations whenever I try to do anything deeper than a simple select.
Do you have experience with python on and/or interfacing with the as400? Any suggestions on a good place to go to learn?
LikeLike