【Python连接数据库】Python连接Teradata数据库-TD SQL Driver 方式(teradatasql包)

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 () ]

执行结果如下:

 

 

官方说明文档:

Teradata SQL Driver for Python

转载于:https://www.cnblogs.com/badboy200800/p/11234144.html

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值