无法找到从未知到布尔错误的转换函数

时间:2015-07-02 22:09:46

标签: python sql postgresql psycopg2

lvalue required as left operand of assignment

上面的python / psycopg2代码给出了以下错误:

query = """UPDATE table SET last_tracked = %s, being_tracked = %s WHERE(
                SELECT 'X' FROM temp_table
                WHERE table.selected_id = temp_table.selected_id);"""
cur.execute(query, [datetime.utcnow().isoformat(' ').split('.')[0] + ' z', True])

以下代码完美无缺:

ERROR:  failed to find conversion function from unknown to boolean
STATEMENT:  UPDATE table 
            SET last_tracked = '2015-07-02 20:32:00 z', being_tracked = true 
            WHERE(
                SELECT 'X' FROM temp_table
                WHERE table.selected_id = temp_table.selected_id);

我尝试仅更新表中已存在的行。我在这里做错了什么?

1 个答案:

答案 0 :(得分:1)

你错过了WHERE谓词中的EXISTS:

query =“”“UPDATE表SET last_tracked =%s,being_tracked =%s WHERE(                 从temp_table中选择“X”                 table.selected_id = temp_table.selected_id);“”“

应该是:

query =“”“UPDATE表SET last_tracked =%s,being_tracked =%s WHERE EXISTS(                 从temp_table中选择“X”                 table.selected_id = temp_table.selected_id);“”“

不要?