blue-yonder / turbodbc

Turbodbc is a Python module to access relational databases via the Open Database Connectivity (ODBC) interface. The module complies with the Python Database API Specification 2.0.
http://turbodbc.readthedocs.io/en/latest
MIT License
607 stars 85 forks source link

Create stored procedure failed on Teradata #245

Open anfrolov opened 4 years ago

anfrolov commented 4 years ago

I'm trying to create procedure on Teradata using turbodbc. There is my sample code:

import turbodbc
with turbodbc.connect(dsn="my_dsn") as con:
    with con.cursor() as cur:
        cur.execute("""create procedure dev.test_procedure () 
        sql security invoker 
        begin 
            delete dev.test_table ; 
        end ; 
        """)

I have got this error:

DatabaseError: ODBC error
state: 42000
native error code: -3706
message: [Teradata][ODBC Teradata Driver][Teradata Database] Syntax error:
Invalid  SQL Statement.

But, the same code works with no errors in Teradata SQL Assistant. Also, this code works fine if I use teradatasql:

import teradatasql
with teradatasql.connect(
    '{"host":"my_host","user":"my_user","password":"my_password"}'
) as con:
    with con.cursor() as cur:
        cur.execute("""create procedure dev.test_procedure () 
        sql security invoker 
        begin 
            delete dev.test_table ; 
        end ; 
        """)
fjetter commented 4 years ago

I'm not too familiar with Teradata (or teradatasql for that matter). My first gut feeling is that the teradatasql package maybe performs some tokenization / sql parsing or some kind of preprocessing (e.g. stripping whitespaces, etc.) which we do not do. Can you try it with an even simpler statement?