psql查询中的Python列表作为参数

时间:2018-10-12 14:26:14

标签: python sql pandas

我尝试了以下代码,以便使用hadm list运行查询        在查询内部,但最后。

hadm = [1,2,3,4,5,6,7,8,9]
placeholder= '?'
placeholders= ','.join(placeholder for unused in hadm)

sql_lab = """SELECT admissions.hadm_id as hadm_id, min(charttime) as first_lab
FROM mimic2v26.labevents JOIN mimic2v26.admissions using(subject_id) 
WHERE admissions.hadm_id in (%s) AND
charttime - admit_dt > interval '-48 hours'
GROUP BY admissions.hadm_id"""%placeholders

cur.execute(sql_lab,hadm)

我遇到以下错误:

ProgrammingError                          Traceback (most recent call last)
<ipython-input-156-2263cc2076d2> in <module>()
      7 charttime - admit_dt > interval '-48 hours'
      8 GROUP BY admissions.hadm_id"""%placeholders
----> 9 cur.execute(sql_lab,hadm)

ProgrammingError: syntax error at or near ","
LINE 3: WHERE admissions.hadm_id in (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?...
                                  ^

0 个答案:

没有答案