On 21/01/2013 15:57, David Lee wrote:
--
Because "treat as" is an assertion designed so the query author can
tell a pessimistic static type checker to get out of the way and mind
its own business, it is needed only in systems that do pessimistic
static type checking, which are very few and far between. (Galax and
SQL Server are the only ones that come to mind).
Michael Kay
Saxonica
----
Do you know of any cases where "treat as" is necessary in XQuery ?
Or is it the equivalent of a static assert that otherwise would cause
a dynamic error ?
It's only ever needed in systems that do pessimistic static typing. For
example if you have a function
declare function local:f($p as element(p)) as xs:integer {
$p/@age
}
then because element(p) matches any element whose name is p, regardless
of schema validity, then the system won't be able to work out that @age
is an integer, and will reject this as unsafe. So you have to do
declare function local:f($p as element(p)) as xs:integer {
data($p/@age) treat as xs:integer
}
which is of course painful, which is why most systems have chosen to go
with weaker static type checking.
Michael Kay
Saxonica
_______________________________________________
[email protected]
http://x-query.com/mailman/listinfo/talk