Teradata Python 模块显示 table 语句不起作用

Teradata Python module show table statement does not work

我正在试验 Teradata-Python module,我是 python

的新手

我试图在 SHOW TABLE 语句的帮助下获取 table ddl,它的行为很奇怪,整个 DDL 中只有 returns 几个字。请在下面查看我的尝试和错误

import teradata
class DB():
    def __init__(self):
        udaExec = teradata.UdaExec (appName="test", version="1.0",logConsole=False)
        session = udaExec.connect(method="odbc", system="tddemo",username="dbc", password="dbc")
        self.session = session

    def fun1(self):
        # session.execute("create table financial.dummytable1(a varchar(10))")
        rows = self.session.execute("SHOW TABLE financial.dummytable1")
        for row in rows:
            print(row)
db = DB()
db.fun1()

print("---The End---")

这是意外的结果

PRIMARY INDEX ( a );]HARACTER SET LATIN NOT CASESPECIFIC)CK ,
---The End---

想要的结果

CREATE SET TABLE financial.dummytable1 ,NO FALLBACK ,
     NO BEFORE JOURNAL,
     NO AFTER JOURNAL,
     CHECKSUM = DEFAULT,
     DEFAULT MERGEBLOCKRATIO
     (
      a VARCHAR(10) CHARACTER SET LATIN NOT CASESPECIFIC)
PRIMARY INDEX ( a );
---The End---

请帮助我了解这里发生了什么。

这是 Teradata Python 模块的已知问题。您可以在 Teradata Python Module 页面的评论中看到有人遇到了完全相同的问题。值得庆幸的是,他们找到了解决方案,并在稍后发表了一些评论后给了我们一个解决方法:

The reason the results of SHOW TABLE were not displayed properly on the terminal is because the newline characters in the result were mostly likely carriage returns instead of line feeds. To ensure it displays correctly, you can split the output based on the presence of any newline sequence and print the lines individually. E.g.

import re
for line in re.split("\r\n|\n\r|\r|\n", row[0]):
    print(line)

其中还包含一些其他陷阱。似乎是一个很好的收藏夹。