Teradata Python模块show table语句

2024-04-20 09:00:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在试用Teradata-Python module,我对python还不熟悉

我试图在SHOW table语句的帮助下获取表ddl,它的行为很奇怪,只返回整个ddl中的几个单词。请看下面我的尝试和错误

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---")

这是意想不到的结果

^{pr2}$

期望的结果

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---

请帮我弄清楚这里发生了什么事。在


Tags: noselfexecutedbsessiondefshowtable
1条回答
网友
1楼 · 发布于 2024-04-20 09:00:41

这是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)

还有一些其他的陷阱也被抓到了。似乎是个很好的书签。在

相关问题 更多 >