RE: Valid use of the Where clause

Many thanks Mr Robie.  The results you highlighted below are exactly what we
were getting but not expecting.  We changed the let to a for and all works
great.
Thanks for your reply
Shane


-----Original Message-----
From: Jonathan Robie [mailto:jonathan.robie@datadirect-technologies.com]
Sent: Friday, March 21, 2003 3:20 PM
To: McMillan, Shane; 'public-qt-comments@w3.org'
Subject: Re: Valid use of the Where clause


At 01:55 PM 3/21/2003 -0700, McMillan, Shane wrote:
>I have been reading the specs on 1.0 working draft for XQuery regarding 
>the where clause.  It does not seem to support the following syntax:
>Let $a := input()/person/lastname
>Where $a = "miller"<?xml:namespace prefix = o ns = 
>"urn:schemas-microsoft-com:office:office" />
>Return $a

If you delete "<?xml:namespace prefix = o ns = 
"urn:schemas-microsoft-com:office:office" />" and change the case of your 
keywords to lowercase, this parses fine according to our grammar:

         let $a := input()/person/lastname
         where $a = "miller"
         return $a

It's often helpful to try out queries on our test grammar page if you're 
not sure whether a given query parses:

         http://www.w3.org/2002/08/applets/xqueryApplet.html

>Notice in the where clause there is no further navigation down the tree 
>because this query wants all documents with lastname = to miller.  All 
>spec examples do not show this usage of the where clause.  Is the above 
>query syntactically correct based on the 1.0 standards?

Our BNF accepts this query just fine. You might be a little surprised by 
what it means! To explain why, let me add in a little data:

let $in := <people>
                <person><lastname>robie</lastname></person>
                <person><lastname>miller</lastname></person>
            </people>
let $a := $in/person/lastname
where $a = "miller"
return $a

What do you expect this to return? It returns the following:

   <lastname>robie</lastname>
   <lastname>miller</lastname>

To explain why, let me step through this one clause at a time:

let $a := $in/person/lastname

    $a is bound to:
         <lastname>robie</lastname>,
         <lastname>miller</lastname>

where $a = "miller"

     this is approximately equivalent to:

         where some $dot in $a satisfies $dot eq miller

return $a

      since the where clause evaluates to true,
      this returns $a

That's why for/where is more common than let/where, but let/where is very 
helpful with aggregate functions like sum(), count(), avg(), min(), and
max().

Is that helpful?

Jonathan

Received on Friday, 21 March 2003 16:44:12 UTC