将Teradata SQL结果打印到命令行 - Python

时间:2017-09-12 17:17:03

标签: python teradata

我有正确执行的脚本,但我想将SQL脚本的结果打印到屏幕上。需要添加什么?

由于

import teradata
import sys
import pwd

def main():

    udaExec = teradata.UdaExec (appName="DataWarehouseConnectionTest", version="1.0", logConsole=True)

    mConn = udaExec.connect(method="odbc",dsn="test",username=pwd.username,password=pwd.password)

    mConn.execute('SELECT COUNT(*) FROM DB.Test')

if __name__ == "__main__":
main()

1 个答案:

答案 0 :(得分:2)

您应该能够通过直接循环表达式来打印查询结果:

for line in mConn.execute('SELECT COUNT(*) FROM DB.Test'):
    print(line)

或者在你的情况下:

res = mConn.execute('SELECT COUNT(*) FROM DB.Test')
if res:
    print(res[0])