[xquery-talk] using OR in xquery expression

Jeff Dexter jeff.dexter at rainingdata.com
Thu May 18 14:01:08 PDT 2006


Titash,

	Your query should work as you expect. I can't speak to why exist
isn't returning the correct results, but I've suggested a re-write below
that may work. The use of the combo predicate/where as well as re-iterating
over the data in $p while applying restrictions to $r may be why exist isn't
working for this query. I ran your query against TigerLogic and it ran fine.

	The following query <em>may</em> work for you as it eliminates some
of the oddities, though I can't guarantee it models your original intent,
and I haven't tested it against exist.

	for $r in //section
	where $r/sectioninfo/keywordset/keyword
		[@role="subject" and . ="Explanation"]
	return
		for $p in $r/sectioninfo/keywordset/keyword
			[ @role = 'objrel' or @role = 'subrel' ]
		where $p = 'scan-status'
		return
			$r

	I eliminated the combo predicate/where and simplified the secondary
ForExpr, so the query is a little simpler and should return your intended
result, but again, I haven't tried it against exist, so I can't guarantee it
will get you over the hump (but it's worth a try...)

	Having said all that, if it turns out the OrExpr is the problem, you
can always try

	@role = ( 'objrel', 'subrel' )

instead of

	@role = 'objrel' or @role = 'subrel'

	Anyway, there are a lot of ways to write this, which is why some
optimizers have differing degrees of luck in optimizing it the right way.

Jeff Dexter.
Chief Architect, TigerLogic
www.rainingdata.com

-----Original Message-----
From: talk-bounces at xquery.com [mailto:talk-bounces at xquery.com] On Behalf Of
Titash Neogi
Sent: Thursday, May 18, 2006 3:28 AM
To: talk at xquery.com
Subject: [xquery-talk] using OR in xquery expression

Dear XQuery Experts,


Please consider the following XML extracts

__EXTRACT A__

<sectioninfo>
        <keywordset>
            <keyword role="infotype">reference</keyword>
            <keyword role="subject">Explanation</keyword>
            <keyword role="subrel">scan-status</keyword>
          
        </keywordset>
    </sectioninfo>


__EXTRACT B__

<sectioninfo>
        <keywordset>
            <keyword role="infotype">reference</keyword>
            <keyword role="subject">Explanation</keyword>
            <keyword role="objrel">scan-status</keyword>
          
        </keywordset>
    </sectioninfo>


Now please consider the following query below

	for $r in //section where
$r/sectioninfo/keywordset/keyword[@role="subject"]= "Explanation" return


(for $p in //section where 
($r/sectioninfo/keywordset/keyword[@role="objrel"]="scan-status") 
or 
($r/sectioninfo/keywordset/keyword[@role="subrel"]="scan-status") return
$p)

Given this XQuery, the database returns only Extract B (where the objrel
value is "scan status") but does not return Extract A (where subrel
value is "scan status")

I am unable to understand why this is happening since I am using OR so
that either of the two expressions should return a result.

Please guide me on this.
FYI, I am using the exist XML DB.

Thanks and Regards
Titash Neogi


_______________________________________________
talk at xquery.com
http://xquery.com/mailman/listinfo/talk





More information about the talk mailing list