尝试使用 teradataml copy_to_sql 函数上传 pandas 数据框

Trying to upload a pandas dataframe using teradataml copy_to_sql function

我对将数据上传到 teradata 还很陌生。我知道有效的方法是使用插入语句逐行插入,但我想避免这种情况。我正在尝试将我的熊猫数据框直接上传到 teradata 但尚未成功。我已经尝试了 2 种方法,我的偏好是让方法 1 起作用,但我想先得到一个有效的解决方案。

我试过两种方法。
1.Teradataml 模块 - copy_to_sql 2.Teradata 模块 - 使用插入语句

方法 1:使用 copy_to_sql 函数

创建 table
from teradataml.dataframe.copy_to import copy_to_sql
from teradataml import create_context, remove_context

df # some dataframe

table_name="db.table"
copy_to_sql(df = df_new, table_name = "db.table", primary_index="index", if_exists="replace")

方法2:使用插入语句

添加到已经创建的table
import teradata

udaExec = teradata.UdaExec (appName=appname, version="1.0", logConsole=False)
connect = udaExec.connect(method="odbc",system=host, username=user,
                            password=passwrd)

num_of_chunks=100
table_name="db.table"
query='INSERT INTO '+table_name+' values(?,?,?,?,?);'
df_chunks=np.array_split(df_new2, num_of_chunks)
for i,_ in enumerate(df_chunks):
    data = [tuple(x) for x in df_chunks[i].to_records(index=False)]
    connect.executemany(query, data,batch=True)

**method 1** get the following error related to access.  Not sure while the SQL statement is adding quotes for the bolded table below:
OperationalError: (teradatasql.OperationalError) [Version 16.20.0.48] [Session 5229096] [Teradata Database] [Error 3524] The user does not have CREATE TABLE access to database U378597.
[SQL: 
CREATE multiset TABLE **"db.table"** (
    "PBP" VARCHAR(1024) CHAR SET UNICODE, 
    recon VARCHAR(1024) CHAR SET UNICODE, 
    date2 TIMESTAMP(6), 
    "CF" FLOAT, 
    "index" VARCHAR(1024) CHAR SET UNICODE
)
primary index( "index" )

]
**method 2** get a error about inserting dates.  Assume datetime needs to be converted in someway to work in teradata table but unsure how

DatabaseError: (6760, '[HY000] [Teradata][ODBC Teradata Driver][Teradata Database] Invalid timestamp. ')

table_name 是一个不合格的名称。要指定应在其中创建 table 的 Teradata "database",请使用单独的 schema_name 参数。

对于 "method 2",考虑使用 teradatasql 包而不是 teradata。或者我想你可以 .isoformat(' ') 时间戳。