
Signature
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
> > I am trying to figure out if a UDF can accept a UDT (User-defined Distinct
> > Type, *not* structured type) as one of its parameters. I'm running DB2 for
[quoted text clipped - 41 lines]
> For a UDT the implementation of the external UDT will simply use the
> basetype (e.g. integer). As long as teh basetype exists you're cool.
So, since my ShoesizeEuropean is based on an Integer, there is no problem?
That's very useful to know. So, if I understand you correctly, my CREATE
FUNCTION needs to refer to integer rather than ShoesizeEuropean in the input
and output parameters. Is that correct?
Also, does the SQL statement that invokes the UDF need to convert the
distinct type to the base type manually or does this happen "automagically"?
For example, do I need this in my SQL (where convert() is the function that
changes European shoesizes to North American and euro_size is the name of
the column containing the European show size:
select id, name, convert(cast (euro_size as int)) ...
or will the cast happen "automagically" if I do this:
select id, name, convert(euro_size) ...
> When dealing with UDT you can also look at sourced functions and SQL
> Functions.
> If your american2europeansizes fucntion just is a fancy expression an
> SQL Function should beat Java in performance hands down.
That's also very useful to know. However, the Java UDFs will tend to be more
complex than a shoe size conversion; I just used shoe sizes as a simple
example ;-)
Rhino
Serge Rielau - 30 Mar 2005 20:07 GMT
>>For a UDT the implementation of the external UDT will simply use the
>>basetype (e.g. integer). As long as teh basetype exists you're cool.
[quoted text clipped - 3 lines]
> FUNCTION needs to refer to integer rather than ShoesizeEuropean in the input
> and output parameters. Is that correct?
The CREATE FUNCTION statement uses the UDT.
Your java implementation uses the base type.
UDT's are purely a game of the SQL Compiler frontend to enforce type
safety. The optimizer and runtime don't know they exist.
> Also, does the SQL statement that invokes the UDF need to convert the
> distinct type to the base type manually or does this happen "automagically"?
It's what we call a no-op cast. runtime doesn't waste a cycle. Just like
the C usage of a typedef does not change the executable.
> For example, do I need this in my SQL (where convert() is the function that
> changes European shoesizes to North American and euro_size is the name of
[quoted text clipped - 5 lines]
>
> select id, name, convert(euro_size) ...
Given that convert() was CREATEd to accept the UDT only teh later will
work. if you try the first DB2 will give you a function not found error.
Not sure how much epxerience you have with UDT, but make sure the schema
of the UDT is in your PATH. Otherwise DB2 will not find either casts or
comparisons.
>>When dealing with UDT you can also look at sourced functions and SQL
>>Functions.
[quoted text clipped - 4 lines]
> complex than a shoe size conversion; I just used shoe sizes as a simple
> example ;-)
And I was about to ask you for the conversion table I still confuse the
local retailers by telling them my German shoesize ;-)
Cheers
Serge

Signature
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab