1.Python安裝
詳見文檔:Python連接Teradata數據庫-ODBC方式
2.使用teradatasql連接TD數據庫
Teradata SQL驅動(Python)下載地址:teradatasql-16.20.0.42-py3-none-any.whl
(1)使用pip安裝或升級(macOS or Linux系統)
pip install teradatasql-16.20.0.42-py3-none-any.whl #安裝 pip install --no-cache-dir -U teradatasql #升級
安裝teradatasql時,出現錯誤Could not find a version that satisfies the requirement pycryptodome.可參考如下文檔解決:安裝teradatasql提示找不到pycryptodome模塊錯誤
(2)使用pip安裝或升級(Windows系統)
py -3 -m pip install teradatasql-16.20.0.42-py3-none-any.whl #安裝 py -3 -m pip install --no-cache-dir -U teradatasql #升級
(3)驗證安裝成功
安裝完畢后,在Python安裝目錄/usr/local/python3/下,新增teradatasql文件夾(測試py文件)。在第三方包目錄/usr/local/python3/lib/python3.6/site-packages 下新增teradatasql文件夾即為成功。
(4)測試腳本
/usr/local/python3/teradatasql/samples/BatchInsert.py
# Copyright 2018 by Teradata Corporation. All rights reserved. # This sample program demonstrates how to insert a batch of rows. import teradatasql with teradatasql.connect ('{"host":"192.168.253.131","user":"dbc","password":"dbc"}') as con: with con.cursor () as cur: cur.execute ("create volatile table voltab (c1 integer, c2 varchar(100)) on commit preserve rows") cur.execute ("insert into voltab (?, ?)", [ [1, "abc"], [2, "def"], [3, "ghi"]]) cur.execute ("select * from voltab order by 1") [ print (row) for row in cur.fetchall () ]
執行結果如下:

