Using odbc API in Teradata UDF's written in C

General
Enthusiast

Using odbc API in Teradata UDF's written in C

Hi there,

I need to create a UDF in C to connect to a teradata server dynamically....can this be written using the ODBC API and then integrate this function into the teradata dictionary or will I have to use CLI to do this task?????

What I actually want is to create a UDF and using it want to run queries like CREATE, SELECT and INSERT on a table. The server ip database name and all is entered by the user. I wrote a code for this using ODBC. But now I want to integrate it into teradata as a UDF. Will the ODBC connectivity work???

Tags (2)
3 REPLIES
Teradata Employee

Re: Using odbc API in Teradata UDF's written in C

No, ODBC is not supported for use in a UDF. Actually, no SQL requests are supported in a UDF -- neither CLI nor JDBC are supported in a UDF.

SQL requests using the "default connection" are only supported for External Stored Procedures. An External Stored Procedure written in C can use CLI (but not ODBC) to execute SQL requests. An External Stored Procedure written in Java can use JDBC to execute SQL requests.

Enthusiast

Re: Using odbc API in Teradata UDF's written in C

Hi...Thanks for your reply...but I still have a doubt...Like the examples given here http://developer.teradata.com/connectivity/reference/odbc-learning-examples we can use SQLDriverConnect() to connect to a database and use SQLExecDirect() to execute the SQL queries and fetch their result using the SQLBind() and SQLFetch() functions using the ODBC API.....I want to implement something similar using Teradata UDFs. Is that possible?? I understand that I cannot use ODBC in Teradata UDFs but is there any other way for me to connect to a Teradata Database and execute and fetch the result using the Teradata UDF written in C??? 

As mentioned in the above reply I cannot execute SQL requests using ODBC but in the examples it shows I can...Is there something I am understanding wrong??

Teradata Employee

Re: Using odbc API in Teradata UDF's written in C

>>> use SQLDriverConnect() to connect to a database and use SQLExecDirect() to execute the SQL queries and fetch their result using the SQLBind() and SQLFetch() functions using the ODBC API.....I want to implement something similar using Teradata UDFs. Is that possible?

No, that is not possible in a UDF.

>>> is there any other way for me to connect to a Teradata Database and execute and fetch the result using the Teradata UDF written in C?

As I said in my previous post, SQL requests are not supported in a UDF. External Stored Procedures can execute SQL requests. An External Stored Procedure written in C can use CLI (but not ODBC) to execute SQL requests. An External Stored Procedure written in Java can use JDBC to execute SQL requests.

>>> in the examples it shows I can...Is there something I am understanding wrong?

The ODBC example programs are client-side programs, meaning they are only intended to run on a client machine, not run on the database machine. The ODBC example programs do not show UDFs executing SQL requests.