Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将元组从pandas导出到sql_Python_Sql_Postgresql_Jupyter Notebook_Psycopg2 - Fatal编程技术网

Python 将元组从pandas导出到sql

Python 将元组从pandas导出到sql,python,sql,postgresql,jupyter-notebook,psycopg2,Python,Sql,Postgresql,Jupyter Notebook,Psycopg2,我在jupyter笔记本中工作,我想将元组导出到sql(在where条件下)。但是id不起作用 numb = ('1','2', '3') query = """ SELECT * from table where table.number in numb """ conn = psycopg2.connect(dbname='dbname', user='user',

我在jupyter笔记本中工作,我想将元组导出到sql(在where条件下)。但是id不起作用

numb = ('1','2', '3')


query =  """ SELECT *
              from table
              where table.number in numb """

conn = psycopg2.connect(dbname='dbname', user='user', 
                        password='pass', host='host' ,port ='port')
但这是有效的

query =  """ SELECT *
              from table
              where table.number in ('1','2', '3') """

conn = psycopg2.connect(dbname='dbname', user='user', 
                        password='pass', host='host' ,port ='port')

您差一英寸就错过了,下面的代码应该可以工作:

numb = ('1','2', '3')


query =  f""" SELECT *
              from table
              where table.number in {numb} """

conn = psycopg2.connect(dbname='dbname', user='user', 
                        password='pass', host='host' ,port ='port')

打印(查询)
的输出:

请注意,还有其他几种方法。你需要看看python

numb = ('1','2', '3')


query =  """ SELECT *
              from table
              where table.number in {} """.format(numb)

conn = psycopg2.connect(dbname='dbname', user='user',
                        password='pass', host='host' ,port ='port')
 SELECT *
              from table
              where table.number in ('1', '2', '3')