Consistent SQL Generation

In XQuery, many queries may be semantically equivalent. DataDirect XQuery® recognizes common equivalences in queries and ensures that efficient SQL is generated for all the different ways of expressing a query.

Example 17. SQL Generation for Equivalent Queries

XQuery (all of these queries are equivalent)

collection("USERS")/USERS/FIRSTNAME[.='John']

collection("USERS")//FIRSTNAME[.='John']

collection("USERS")/USERS[FIRSTNAME='John']/FIRSTNAME

for $u in collection("USERS")/USERS
where $u/FIRSTNAME = 'John'
return $u/FIRSTNAME

declare function local:testUser($firstname) {$firstname = 'John'};
for $u in collection("USERS")/USERS
where local:testUser ($u/FIRSTNAME)
return $u/FIRSTNAME

for $u in collection("USERS")/USERS
return if ($u/FIRSTNAME = 'John') then $u/FIRSTNAME else ()

Generated SQL (generated for all the above queries)

SELECT ALL
nrm6."FIRSTNAME" AS RACOL1
FROM
"PEPPINO"."USERS" nrm6
WHERE
nrm6."FIRSTNAME" = 'John' AND
LENGTH(nrm6."FIRSTNAME") = LENGTH('John')

Try DataDirect XQuery® Free!

Put the power, scalability, and performance of DataDirect XQuery® to work for you today! Our free trial lets you see for yourself how easy it is to build data integration applications that access relational, EDI, and other file formats as XML!

Download DataDirect XQuery® today!

Online Video Tutorials!

Our easy-to-follow online video tutorials are a great way to get acquainted with the many features of DataDirect XQuery®.

And if you like what you see, download a free copy today and try DataDirect XQuery® for yourself!

Stay Informed!

XQuery is one of the hottest XML technologies being developed today. Stay informed with vital news about standards, tools, and trends by signing up for the DataDirect XQuery® newsletter.