Teradata Python Module

Tools
Tools covers the tools and utilities you use to work with Teradata and its supporting ecosystem. You'll find information on everything from the Teradata Eclipse plug-in to load/extract tools.
Teradata Employee

Re: Teradata Python Module

@alpanchino - There was a bug that was preventing the ODBC driver from using the specified DSN.  A fixed has been committed and an update released (15.10.00.06).  Thanks for reporting.

Teradata Employee

Re: Teradata Python Module

How do I find out what the error code is returned from executed sql statement. I dont want python to exit when a sql statement returns an error but I want to do some processing when a error occurs

Teradata Employee

Re: Teradata Python Module

@cw171001 - Here is an example:

try:
session.execute("INVALID")
except teradata.DatabaseError as e:
print(e.code)

Re: Teradata Python Module

It would be nice if we could get more granular control over logging levels. I like INFO level as a default but when running batch INSERTS with thousands of rows this actually logs every row passed to the INSERT statement resulting in a very large log file. I created my own logger and tried to change logging level to WARNING just for the INSERT using Python standard logger.setlevel function but that doesn't seem to work. Setlevel executes successfully but it does not seem to affect what is actually logged by Teradata module.

It would be great if there was an option to override session logging level through a parameter to Execute/Executemany.  

Teradata Employee

Re: Teradata Python Module

@psobczak - Good suggestion.  I created an enhancement request on github for this feature.

Enthusiast

Re: Teradata Python Module

Would it possible to make UdaExecConnection importable? A use case would be to have the connect object passed between functions. e.g.

def teradata_connect(configFile='udaexec.ini', logLevel='CRITICAL') :

    udaExec = teradata.UdaExec(appConfigFile=configFile, logLevel=logLevel)

    try:

         session = udaExec.connect("${dataSourceName}")

         return session

    except Exception as e :

        print "Error connecting to Teradata : ${dataSourceName}"

        raise e

def teradata_disconnect(session) :

    if session is not None :

    #if isinstance(session, UdaExecConnection) :

        try:

            session.close()

        except e :

            print "Error closing connection"

Teradata Employee

Re: Teradata Python Module

@seabull - You can import it using "from teradata.udaexec import UdaExecConnection", but I would not recommend it as its not part of the interface exposed by UdaExec and could change at any time in the future.  Its not clear why you would even want to do that, Python's duck typing makes it so you shouldn't need to care what the underlying type is, you can pass the connection object to different methods without importing UdaExecConnection.   In your example, it appears you want to check if its a UdaExecConnection instance to test wheter to call close.   A more pythonic way to do that, assuming any old object will be passed to the disconnect method would be to test for the existence of a close method on the passed in object.  E.g.

closeOp = getattr(session, "close", None)

if callable(closeOp):

    session.close()

Teradata Employee

Re: Teradata Python Module

Does the queryTimeout parameter accept only ints? Is there any way for it to accept decimals/floats?

Teradata Employee

Re: Teradata Python Module

@ryanv -  Yes, the query timeout parameter only supports integers.  Fractional second timeouts are not supported by ODBC.  

Enthusiast

Re: Teradata Python Module

@ericscheie, Thanks! This is very helpful.