I have a series of SQL scripts. I want to use Python to read each of those files and execute that code against Netezza. Here's what I've got so far, but it doesn't seem to actually do anything.
My SQL script (this table starts with plenty data in it, just want to test if I can truncate it for now. The actual code I plan to run will continue by creating new tables and executing other SQL):
/* DROP THE OLD BACKUP */
TRUNCATE TABLE DB_LAB..MY_TEST
;
My Python code:
import pyodbc
cnxn = pyodbc.connect('DSN=DB_LAB')
cursor = cnxn.cursor()
sql_example = "F:\\My Documents\\test_sql.txt"
infile = open(sql_example ,'r')
lines = infile.readlines()
print lines
>>>['/* DROP THE OLD BACKUP */ \n',
'TRUNCATE TABLE DB_LAB..MY_TEST\n',
';\n']
sql = (' '.join(lines))
cnxn.execute(sql)
cnxn.close()
After I execute this code I get no errors but MY_TEST hasn't been truncated.