【问题标题】:problem with spaces added while running queries with the teradatasql package使用 teradatasql 包运行查询时添加空格的问题
【发布时间】:2022-01-18 09:25:38
【问题描述】:

在比较两种在 Python 下运行 Teradata 查询的方法时,我注意到使用 teradatasql 的方法在 varchar 类型的列中添加了空格。

方法一(不加空格)

import teradata
import pandas 

... #defining connection credentials
udaExec = teradata.UdaExec(appConfigFile = ConfigPath, 
     logFile = LogPath, logLevel = LogLev, logConsole=False)
session = udaExec.connect(method = 'odbc', system = hostname, 
     username= usn, password=pwd,driver = drv)

output = pandas.read_sql(query, session)

方法二(加空格)

import teradatasql
import pandas

... #defining connection credentials
with teradatasql.connect (host = hostname, user= usn, password= pwd) as conn:
   output = pandas.read_sql(query, conn)

您能帮我找到解决此问题的方法吗?

【问题讨论】:

  • 我怀疑填充实际上是用于 CHAR 而不是 VARCHAR 类型的列。填充是teradatasql 始终使用 UTF8 会话字符集(本质上是可变长度)的结果,而使用 ODBC 驱动程序显然默认为(固定长度)ASCII 会话字符集。您可以 TRIM 查询中的 CHAR 列(使结果为 VARCHAR)以消除填充。

标签: python sql pandas teradata


【解决方案1】:

我同意 Fred 的分析。此处记录了字符导出宽度问题:https://github.com/Teradata/python-driver#CharacterExportWidth

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-07
    • 2017-09-23
    • 1970-01-01
    • 2014-06-27
    相关资源
    最近更新 更多