home
about
services
contact

Where am I?

XQuery is complicated

April 29, 2007 at 09:31 PM | categories: XQuery | View Comments

It's a rare week when I don't discover some new corner of the language that I didn't know about before. Did you know about per-variable typing?

let $a as xs:integer := 1
return $a + 2
=> 3

Sounds useless, doesn't it? But just like function-parameter typing, it could prevent errors. Think about this:

let $a as element(ArticleTitle) :=
  doc($ID)/MedlineCitation/Article/ArticleTitle
return $a
Now we have a guarantee that there will be exactly one ArticleTitle. Anything else will cause an error:
XDMP-AS: let $a as element(ArticleTitle) :=
  doc($ID)/child::MedlineCitation/child::Article/child::ArticleTitle
  return $a -- Invalid coercion: () as element(ArticleTitle)
Nice, isn't it?

blog comments powered by Disqus