XQuery Built-in Functions

XQuery has a large library of built-in functions, which are all supported by DataDirect XQuery. The vast majority of these are translated into SQL. For some of these functions, the translation is straightforward; for others, the translation requires more thought. We do not know of another XQuery implementation in which such a high proportion of XQuery functions are executed directly in the database.

Example 13. A Straightforward Built-in Function

XQuery

for $u in collection('USERS')/USERS
return concat($u/FIRSTNAME,$u/LASTNAME)

Generated SQL

SELECT ALL
{fn CONCAT(nrm5."FIRSTNAME",nrm5."LASTNAME")} AS RACOL1
FROM
"PEPPINO"."USERS" nrm5

For most of the functions in the XQuery built-in library, though, translating to efficient SQL is non-trivial. DataDirect XQuery does this without changing the semantics of the XQuery function.

Example 14. A More Complex XQuery Built-in Function

XQuery

for $u in collection('USERS')/USERS
return substring-before($u/FIRSTNAME, 'lo')

Generated SQL

SELECT ALL
(CASE WHEN
{fn LOCATE('lo',nrm5."FIRSTNAME")} > 0
THEN
{fn LEFT( nrm5."FIRSTNAME", {fn LOCATE('lo',nrm5."FIRSTNAME")} -1)}
ELSE
'' END) AS RACOL1
FROM
"PEPPINO"."USERS" nrm5

This translation uses features found only in Oracle databases along with JDBC escapes that are standard, but not supported by all drivers - and these features are needed to implement substring-before() efficiently. Different features are used on other databases to achieve an efficient and conformant implementation.

Previous

XQuery Global Variables
HomeNext

User-declared Functions