该函数处理sql请求

2024-04-20 13:43:39 发布

您现在位置:Python中文网/ 问答频道 /正文

该函数处理sql请求。它接收参数,其中一个参数可以是“null”或值(uuid), 我需要将此值添加到where。 但是有一个问题,因为使用null 其中param为空,但值为“where param=value”

范例



sql = '''select name from table where param = %s '''
def run_sql(param=None):
    a = db_api(sql, param)
    


Tags: 函数runnamefromsql参数uuidparam
1条回答
网友
1楼 · 发布于 2024-04-20 13:43:39
select name from table where param is not distinct from %s

在sql中,null = nullnull <> null总是计算为false,因为空值被视为未知值,不能被视为彼此相等或不相等

但是两个null值彼此不不同,因此null is not distinct from null的计算结果为true

相关问题 更多 >