Teradata Package for Python Function Reference on VantageCloud Lake | 17.20 - execute_sql - Teradata Package for Python - Look here for syntax, methods and examples for the functions included in the Teradata Package for Python.

Teradata® Package for Python Function Reference on VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Package for Python
Release Number
17.20
Publication Date
November 2022
Content Type
Programming Reference
Publication ID
B700-4500-112K
ft:locale
en-US
ft:lastEdition
2024-02-21
ft:sourceId
FTML
dita:id
TeradataPython_FxRef_Lake_1720
Product Category
Teradata Vantage
teradataml.utils.utils.execute_sql = execute_sql(statement, parameters=None)
DESCRIPTION:
    Executes the SQL statement by using provided parameters.
    Note:
        Execution of stored procedures and user defined functions is not supported.
 
PARAMETERS:
    statement:
        Required Argument.
        Specifies the SQL statement to execute.
        Types: str
 
    parameters:
        Optional Argument.
        Specifies parameters to be used in case of parameterized query.
        Types: list of list, list of tuple
 
RETURNS:
    Cursor object.
 
RAISES:
    TeradataMlException, teradatasql.OperationalError, TypeError, ValueError
 
EXAMPLES:
    # Example 1: Create a table and insert values into the table using SQL.
    # Create a table.
    execute_sql("Create table table1 (col_1 int, col_2 varchar(10), col_3 float);")
 
    # Insert values in the table created above.
    execute_sql("Insert into table1 values (1, 'col_val', 2.0);")
 
    # Insert values in the table using a parameterized query.
    execute_sql(statement="Insert into table1 values (?, ?, ?);",
                parameters=[[1, 'col_val_1', 10.0],
                            [2, 'col_val_2', 20.0]])
 
    # Example 2: Execute parameterized 'SELECT' query.
    result_cursor = execute_sql(statement="Select * from table1 where col_1=? and col_3=?;",
                                parameters=[(1, 10.0),(1, 20.0)])
 
    # Example 3: Run Help Column query on table.
    result_cursor = execute_sql('Help column table1.*;')