使用python代码取消更新行

使用python代码取消更新行,python,postgresql,Python,Postgresql,我使用Python3进行编码,当我要求在高程列上没有值的情况下更新数据库时,很多情况下都没有更新(它们没有值) 我真的很想知道为什么更新函数对某些记录不起作用,即使数据集上存在x和y坐标,并且这些坐标的高程列为空 有什么建议吗?空值测试可以通过两种方式完成:el_2==None或el_2为None 您要做的是检查el_2的值是否等于字符串无 import psycopg2 as p conn = p.connect("dbname=Chicago user=postgres password=a

我使用Python3进行编码,当我要求在高程列上没有值的情况下更新数据库时,很多情况下都没有更新(它们没有值)

我真的很想知道为什么更新函数对某些记录不起作用,即使数据集上存在x和y坐标,并且这些坐标的高程列为空


有什么建议吗?

空值测试可以通过两种方式完成:
el_2==None
el_2为None

您要做的是检查el_2的值是否等于
字符串

import psycopg2 as p
conn = p.connect("dbname=Chicago user=postgres password=admin host=localhost ")
cur = conn.cursor()
cur.execute("select * from chicago_2po_4pgr group by id")
nbrows = cur.rowcount
rows = cur.fetchall()

elev=result[1].text
x=result[0][1].text
y=result[0][0].text

//I'm getting elev,x and y after using api google elevation request

for j in range (0,nbrows):
            xs=str(rows[j][14])
            ys=str(rows[j][15])
            xt=str(rows[j][16])
            yt=str(rows[j][17])
            el_1=str(rows[j][30])
            el_2=str(rows[j][31])
            if x==xs and y==ys and el_1=='None':
                cur.execute("update chicago_2po_4pgr set elev_1=%s where 
                 x1=%s and y1=%s" %(elev,xs,ys))

            if x==xt and y==yt and el_2=='None':
                cur.execute("update chicago_2po_4pgr set elev_2=%s where 
                x2=%s and y2=%s" %(elev,xt,yt))