【发布时间】:2010-12-06 06:40:01
【问题描述】:
想从 cvs 中获取一些缺失值的数据到 postgresql 中。我很高兴使用字符串插入。我想要一个快速的是使用列表或类似的东西来做到这一点。我还需要检查缺失值并替换,否则会出错。
for w in csvReader:
if a ==0:
var = w
sql_table = 'CREATE TABLE TableName (%s)' % ','.join('%s VARCHAR(50)' % name for name in var)
dict_cur.execute(sql_table)
else:
colnum = 0
for col in w:
nms= col
print w, 'column'
#this is not correct
sql_insert = ('INSERT INTO TableName (%s) VALUES (%s)' % (','.join('%s' % name for name in var),','.join('%s' % nm for nm in nms)))
cursor.execute(sql_insert)
colnum += 1
print w
a = a + 1
错误 回溯(最近一次通话最后): 文件“/home/matthew/workspace/dfdsggd/try_db_thing.py”,第 41 行,在 cursor.execute(sql_insert) psycopg2.ProgrammingError:“。”处或附近的语法错误 第 1 行:...ORDER_ADM,MONTH_ADM,DAY_ADM,YEAR_ADM) 值 (2,6,7,.,3,5,7) ^
【问题讨论】:
-
如果你想要一个明确的答案,你的 csv 和表格结构会很好