Teradata Package for Python Function Reference | 20.00 - 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 - 20.00

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Teradata Package for Python
Release Number
20.00
Published
March 2024
Language
English (United States)
Last Update
2024-04-10
dita:id
TeradataPython_FxRef_Enterprise_2000
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.*;')