Unexpected for following namespace declaration

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.:)

One thought on “Unexpected for following namespace declaration

  1. 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?

    Like

Leave a Reply to Pythor Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.