isnull vs is null

后端 未结 10 1374
闹比i
闹比i 2020-12-06 00:13

I have noticed a number of queries at work and on SO are using limitations in the form:

isnull(name,\'\') <> \'\'

Is there a particul

10条回答
  •  情话喂你
    2020-12-06 00:39

    Others have pointed out the functional difference. As to the performance issue, in Postgres I've found that -- oh, I should mention that Postgres has a function "coalesce" that is the equivalent of the "isnull" found in some other SQL dialects -- but in Postgres, saying

    where coalesce(foobar,'')=''
    

    is significantly faster than

    where foobar is null or foobar=''
    

    Also, it can be awesomely dramatically faster to say

     where foobar>''
    

    over

    where foobar!=''
    

    A greater than test can use the index and thus skip over all the blanks, while a not-equal test has to do a full file read. (Assuming you have an index on the field and no other index is used in preference.)

提交回复
热议问题