The function processes the sql request. It receives parameters and one of them can be either “null” or a value (uuid), I need to add this value to where. But there is a problem, because with null “where param is null”, but with the value “where param = value”
Example
sql = '''select name from table where param = %s ''' def run_sql(param=None): a = db_api(sql, param)
Advertisement
Answer
select name from table where param is not distinct from %s
In sql, null = null
and null <> null
always evaluate to false
because null values are treated as unknown and can’t be considered equal or unequal to each other.
But two null
values are not distinct from each other, so null is not distinct from null
evaluates to true
.