UDF

Database
Enthusiast

UDF

Hello,
Please give me an example. How to write a UDF.
I have the C language function written. I also have the teradata database and the C compiler on the same machine.

What is the default path on the Teradata Server?

CREATE FUNCTION MYDB.func_a (vara INT)
RETURNS INT
CLASS SCALAR
LANGUAGE C
NO SQL
PARAMETER STYLE SQL
EXTERNAL NAME 'CI!stdio.h' 'CI!conio.h' 'CS!helloworld.c' 'F!main';

Is the above syntax correct? How am I supposed to write the path of the header and the source files?

Please look at the EXTERNAL statement particularly

Thanks,
Nidhi

7 REPLIES
Enthusiast

Re: UDF

Hi,
In http://www.teradataforum.com/
is huge amount of Tips and examples.
eg.http://www.teradataforum.com/is_integer.htm

greetings
stami
Enthusiast

Re: UDF

Hi,
about the syntax above of the EXTERNAL:
here is a exampel for header file and src file for an
installation on the server:

EXTERNAL NAME 'SI!to_number!/my/home/udf/to_number.h!SS!to_number!/my/home/udf/to_number.c'

stami
Enthusiast

Re: UDF

Hello Stami,

Thanks for the reply.

EXTERNAL NAME 'SI!to_number!/my/home/udf/to_number.h!SS!to_number!/my/home/udf/to_number.c'

Is this a Windows or Unix Server?
I am using a Windows Server currently, but after testing the UDF, I will be creating it on a Unix Teradata Server.

In 'SI!to_number!/my/home/udf/to_number.h!SS!to_number!/my/home/udf/to_number.c'

What is to_number before the path address?

Thanks,
Nidhi

Enthusiast

Re: UDF

Is there any setting that I have to enable in Teradata to call the UDFs?

Nidhi
Enthusiast

Re: UDF

Hi the above from me was for unix.

In TD the User Rights create alter and exec functions are nessesary.

Here is the description for W2K found in UDF-Orange book:

Full path specified to W2K server source

CREATE FUNCTION udfSubStr(
strexp VARCHAR(512),
n1 INTEGER,
n2 INTEGER
)RETURNS VARCHAR(512)
LANGUAGE C
NO SQL
EXTERNAL NAME 'SS!sname!c:\program files\ncr\tdat\tdconfig\teradata\tdbs_udf\usr\udf_substr.c!F!udf_substr3'
PARAMETER STYLE SQL;

File is located on the server S and the file type is S source.
The separator character is ! and the name of the server file is sname.
The full path to the file is specified.
The C function name in the file udf_substr3.c is speci-fied
using the function entry option F, udf_substr3.
The specific name defaults to the function name, udfsubstr.

For sname I take the same function name as in the CREATE FUNCTION Clausel

Greetings stami
Enthusiast

Re: UDF

Hiding external c code in a UDF:

I need to be able to hide the external c code for my function for security reasons but am unable to find instructions on how to do this. We do not want anyone to be able to see it when they do a show function.

Is there a way to do this?

Thanks!

Enthusiast

Re: UDF

You can build and distribute C/C++ UDFs without revealing the source code to users or purchasers.

Example: 'CS!myudfsource!C:\mycode\myudfsource.c'

CI!name_on_server!include_file_name

SI!name_on_server!include_file_name

Identifies the name of a C header file that is included with an <#include> statement in C source file. CI indicates the file is located on the client machine. SI indicates the file is located on the Teradata server.

name_on_server specifies the name given to the header file when it is copied from its original location to the Teradata server UDF compile directory. This can be any name that is unique in the Teradata Database system, and need not match the name of the header file itself. name_on_server should not include the .h file name extension.

include_file_name specifies the name of the header file, including a file path if the file is not located in the current working directory. include_file_name must include the .h file extension.

For more detail refer to:


Thanks!!