我對將數(shù)據(jù)上傳到 teradata 還是很陌生。我知道有效的方法是使用插入語句逐行插入,但希望避免這種情況。我正在嘗試將我的熊貓數(shù)據(jù)框直接上傳到 teradata,但尚未成功。我嘗試了 2 種方法,我的偏好是讓方法 1 起作用,但想先獲得一個可行的解決方案。我試過2種方法。1.Teradataml 模塊 - copy_to_sql 2.Teradata 模塊 - 使用插入語句方法 1 :使用copy_to_sql 函數(shù)創(chuàng)建表from teradataml.dataframe.copy_to import copy_to_sqlfrom teradataml import create_context, remove_contextdf # some dataframetable_name="db.table"copy_to_sql(df = df_new, table_name = "db.table", primary_index="index", if_exists="replace")方法2:使用插入語句添加到已創(chuàng)建的表中import teradataudaExec = teradata.UdaExec (appName=appname, version="1.0", logConsole=False)connect = udaExec.connect(method="odbc",system=host, username=user, password=passwrd)num_of_chunks=100table_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 howDatabaseError: (6760, '[HY000] [Teradata][ODBC Teradata Driver][Teradata Database] Invalid timestamp. ')
1 回答

守著一只汪
TA貢獻(xiàn)1872條經(jīng)驗 獲得超4個贊
thetable_name
是一個不合格的名稱。要指定應(yīng)在其中創(chuàng)建表的 Teradata“數(shù)據(jù)庫”,請使用單獨(dú)的schema_name
參數(shù)。
對于“方法 2”,請考慮使用teradatasql
包而不是teradata
. 或者我想你可以.isoformat(' ')
時間戳。
添加回答
舉報
0/150
提交
取消