Python(psycopg2) - 在元组中插入NULL(None)

时间:2018-02-26 20:11:12

标签: python postgresql null tuples nonetype

我很乐意寻求帮助......

我正在尝试使用元组中指定的值将行插入Postgres。它可以工作,直到其中一个值等于None(我想将其存储为NULL)

此版本的curr.execute有效:

dev_id = '6d89cc68-1b1a-11e8-a339-525400005c6c'
ifid = 1
ifname_id = 1
ifmac = 'nomacpaired'
flag = None
time = ts()

db.cursor.execute("""INSERT into device_ifce (dev_id, ifid, ifname_id, ifmac, flags, updated, created ) VALUES (%s, %s, %s, %s, %s, %s, %s)""", (dev_id, ifid, ifname_id, ifmac, flag, time, time))

但这对我来说并不是很方便,我想这样做:

values = (dev_id, ifid, ifname_id, ifmac, flag, time, time)
db.cursor.execute("""INSERT into device_ifce VALUES {}""".format(values))

......我收到错误:

psycopg2.ProgrammingError: column "none" does not exist
LINE 1: ...b1a-11e8-a339-525400005c6c', 1, 1, 'nomacpaired', None, '201...

其他值正常,但无。如果我将“flag = None”替换为str(flag ='foo'),它就可以工作。

所以我的问题是:是否有可能将元组中的一个值设为None或我做错了什么?

感谢您的回答, 丹尼尔

0 个答案:

没有答案