Python 如何使用psycopg2将int列数据设置为null

Python 如何使用psycopg2将int列数据设置为null,python,python-2.7,selenium-webdriver,psycopg2,Python,Python 2.7,Selenium Webdriver,Psycopg2,我有这段代码,我正在尝试将一个数据行值更新为Null,以测试是否可以使用SeleniumWebDriver在前端重新选择它。当我对数据库手动运行sql时,它工作得很好,但是当我尝试用Null参数替换int列时,我得到 下面是堆栈中有意义的部分 cursor.execute(query, (REASONS_CREATED[reason_created], order_id)) DataError: invalid input syntax for integer: "Null" LINE 4:

我有这段代码,我正在尝试将一个数据行值更新为Null,以测试是否可以使用SeleniumWebDriver在前端重新选择它。当我对数据库手动运行sql时,它工作得很好,但是当我尝试用Null参数替换int列时,我得到

下面是堆栈中有意义的部分

cursor.execute(query, (REASONS_CREATED[reason_created], order_id))
DataError: invalid input syntax for integer: "Null"
LINE 4:     reason_created_id = E'Null'
这是我的密码:

def update_reason_created_on_order(order_id, reason_created, environment='test'):
    '''
    Updates an order's reason created.
    '''
    sql_directory = find_path_to_sql_directory()
    with open(os.path.join(sql_directory, 'update_reason_created_on_order')) as sql:
        cursor = setup_database_cursor(environment)
        query = sql.read()
        try:
            cursor.execute(query, (REASONS_CREATED[reason_created], order_id))
        except:
            raise
这是我创建字典查找的空条目

REASONS_CREATED = {'NULL': 'Null'}
这是一个外部文件中的sql

UPDATE
    order
SET
    reason_created_id = %s
WHERE
    order_id = %s;
COMMIT;

我知道psycopg2会自动进行类型转换,并认识到这一点,即创建的id是int类型。有人知道如何将其设置为null吗?此外,该列可以为NULL。

只需使用
None
,这是Python中SQL
NULL的等价物


注意:不是字符串
“None”
,而是Python单例None(不带引号)。

谢谢,这很有意义。