我有以下数据框
CALL_DISPOSITION CITY END INCIDENT_NUMBER
0 ADV-Advised Waterloo Fri, 23 Mar 2018 01:13:27 GMT 6478983
1 AST-Assist Waterloo Sat, 18 Mar 2017 12:41:47 GMT 724030
2 AST-Assist Waterloo Sat, 18 Mar 2017 12:41:47 GMT 999000
我正在尝试将此推送到 IBM DB2 数据库。
我有以下代码:
# IBM DB2 imports
import ibm_db
# instantiate db2 connection
connection_id = ibm_db.connect(
conn_string,
'',
'',
conn_option,
ibm_db.QUOTED_LITERAL_REPLACEMENT_OFF)
# create list of tuples from df
records = [tuple(row) for _, row in df.iterrows()]
# Define sql statement structure to replace data into WATERLOO_911_CALLS table
column_names = df.columns
df_sql = "VALUES({}{})".format("?," * (len(column_names) - 1), "?")
sql_command = "REPLACE INTO WATERLOO_911_CALLS {} ".format(df_sql)
# Prepare SQL statement
try:
sql_command = ibm_db.prepare(connection, sql_command)
except Exception as e:
print(e)
# Execute query
try:
ibm_db.execute_many(sql_command, tuple(temp_records))
except Exception as e:
print('Data pushing error {}'.format(e))
但是,我不断收到以下错误:
Exception: [IBM][CLI Driver][DB2/LINUXX8664] SQL0104N An unexpected token "REPLACE INTO WATERLOO_911_CALLS" was found following "BEGIN-OF-STATEMENT". Expected tokens may include: "<space>". SQLSTATE=42601 SQLCODE=-104
我不明白为什么会这样。我遵循了这个repo中列出的步骤,但我似乎无法让它工作。我究竟做错了什么?请让我知道我可以做出任何澄清。