Python psycopg2将值作为列

Python psycopg2将值作为列,python,sql,postgresql,psycopg2,Python,Sql,Postgresql,Psycopg2,我试图使用psycopg2创建一个表,然后从一些JSON插入外部数据。为此,我定义了2个函数:create_words_table()和insert_data(): 因此,尝试执行它们: if __name__ == '__main__': create_words_table() logger.info("table created") insert_data() logger.info("Records inserted succ

我试图使用psycopg2创建一个表,然后从一些JSON插入外部数据。为此,我定义了2个函数:create_words_table()和insert_data():

因此,尝试执行它们:

if __name__ == '__main__':
    create_words_table()
    logger.info("table created")
    insert_data()
    logger.info("Records inserted successfully")
    
我得到了进一步的错误:

Traceback (most recent call last):
  File "path\to\file", line 178, in <module>
    main()
  File "path\to\file", line 172, in main
    insert_data()
  File "path\to\file", line 148, in insert_data
    cur.execute('''
psycopg2.errors.UndefinedColumn: ОШИБКА:  столбец "word_from_dict" не существует 
                               # ERROR: column "word_from_dict" does not exist ###
LINE 4:         VALUES (word_from_dict, pos_from_dict, case_from_dic...
回溯(最近一次呼叫最后一次):
文件“路径\到\文件”,第178行,在
main()
文件“路径\到\文件”,第172行,主
插入_数据()
文件“路径\到\文件”,第148行,插入\ U数据
当前执行(“”)
psycopg2.errors.UnfinedColumn:С砦ББА:С砦砦砦砦砦砦砦砦砦砦砦
#错误:“word\u from\u dict”列不存在###
第4行:值(单词来自单词,位置来自单词,大小写来自单词)。。。
查看文档,我没有发现应用简单插入查询时有任何错误,也不理解为什么psycopg2将单词值后的元组作为表的字段。
如果有人能澄清这一点,我将不胜感激。

问题在于您的查询,您需要将查询更改为此,并将元组作为参数传递:

cur.execute('''INSERT INTO WORDS (word_, POS_, case_, gender_, mood_, 
        number_, person_, tense_, tonality_, pos_score_, neu_score_, neg_score_) 
   VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)''',handle_dict(word))

非常感谢!真的,它需要两个参数。只需要一点澄清:
,handle\u dict(word)
cur.execute('''INSERT INTO WORDS (word_, POS_, case_, gender_, mood_, 
        number_, person_, tense_, tonality_, pos_score_, neu_score_, neg_score_) 
   VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)''',handle_dict(word))