zoukankan      html  css  js  c++  java
  • 【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

  • 相关阅读:
    python变量和常量
    python运算符
    python 数据类型强制转换
    Python 变量的缓存机制
    Python格式化输出
    Python 自动类型转换
    Python 六大标准基础数据类型
    Python 基础
    pyhton 初识
    计算机基础
  • 原文地址:https://www.cnblogs.com/badboy200800/p/11234144.html
Copyright © 2011-2022 走看看