[xquery-talk] sequence membership operator (in)

Jonathan Robie jonathan.robie at datadirect.com
Mon Feb 13 13:58:45 PST 2006


manavaputra at yahoo.com wrote:

>Hi
>
>I am just curious, if the membership operator like
>"in" of SQL was ever considered in xquery? Right now,
>i see i could do something equivalent using the
>sequence functions  index-of() and empty(), but some
>think like "in" would have been much more concise and
>intutive.
>  
>

This is pretty easy to do in XQuery. Instead of using IN like this:

SELECT * FROM Customers WHERE State IN ('Alabama', 'Alaska',
'California', 'Louisiana', 'Maryland', 'Pennsylvania', 'Tennessee',
'Texas')

Use a general comparison =, which has implicit existential quantification:

for $c in //customer
where $c/state =  ('Alabama', 'Alaska',
'California', 'Louisiana', 'Maryland', 'Pennsylvania', 'Tennessee',
'Texas')
return $c

Hope this helps!

Jonathan

-- 
Read my Blog: http://blogs.datadirect.com/jonathan_robie/
Learn XQuery: http://media.datadirect.com/download/docs/ddxquery/tutorial_query.html
Learn XQJ (the JDBC for XQuery): http://www.datadirect.com/developer/xquery/topics/xqj_tutorial/
Get DataDirect XQuery: http://www.datadirect.com/products/xquery/



More information about the talk mailing list