All Forums General
Jayakumar.mm 4 posts Joined 02/16
07 Apr 2016
Is there a way using Python to create multiple volatile table in teradata

 

0down votefavorite

 

I am using python to create multiple volatile statements in teradata but I am not able to execute more than a table. I am using End Transactions after every create statement. Please help
I am getting two errors:
a. Too many Transaction End statements - If I Transaction End statement for all the create statement b. Only an ET or null statement is legal after a DDL Statement - If I remove Transaction End statement from any of the create statement.
Python code using:
 

import pyodbc
import openpyxl
import csv
import os
from time import gmtime, strftime
from datetime import datetime
import sys
from params import *
cursor = teradata.cursor()
#cursor1 = Mysqldb.cursor()
Mysqldb.timeout = 500
wb = openpyxl.load_workbook("excel.xlsm",keep_vba = True)
ws = wb["Output Scripts"]
ws_1 = wb["DR TT Scripts"]
l = datetime.now()
for i in range(2,50):
exec_par = ws_1.cell(row = i, column = 3).value
if exec_par == 'Y':
for j in range(2,3):
query_1 = ws_1.cell(row = i, column = j).value
ws_1.cell(row = i, column = 3).value = 'N'
if (query_1 != 'NA') and (query_1 != None):
y = datetime.now()
cursor.execute(query_1)
z = datetime.now()
print (z-y)
else:
print "No records"
else:
print "No scripts for execution"
wb.save("excel.xlsm")
for i in range(2,38):
print i
exec_par = ws.cell(row = i, column = 9).value
if exec_par == 'Y':
for j in range(3,4):
#ws.cell(row = i, column = 9).value = 'N'
query = ws.cell(row = i, column = j).value
flag = ws.cell(row = i, column = 15).value
print query
if (query != 'NA') and (query != None):
results1 = cursor.execute(query,multi=True)
rows_count = cursor.rowcount
ws.cell(row = i, column = 6).value = rows_count
print rows_count
columns = [g[0] for g in cursor.description]
filename_txt = "C:\Output_Files" + "\\" + ws.cell(row = i, column = 1).value + "_" + l.strftime('%Y-%m-%d %H_%M_%S') + ".txt"
ws.cell(row = i, column = 9).value = 'N'
print filename_txt
with open(filename_txt, "wb") as csv_txt:
csv_writer = csv.writer(csv_txt, delimiter = '|')
csv_writer.writerow(columns) # write headers
csv_writer.writerows(results1)
csv_txt.close()
else:
ws.cell(row = i, column = 9).value = 0
print ws.cell(row = i, column = 9).value
wb.save("excel.xlsm")
else:
print "No scripts for execution"

 

Willimoa 63 posts Joined 10/09
20 Apr 2016

Is that all of the code ?  Your indenting has gone missing too.
Where was the teradata object defined ?

You must sign in to leave a comment.