Why does PostgreSQL not return null values when the condition is <> true

后端 未结 3 1681
遥遥无期
遥遥无期 2020-12-16 11:53

I was confused behind the reasoning of the following:

SELECT * FROM table WHERE avalue is null

Returns x number of rows where \'avalue\' is

3条回答
  •  独厮守ぢ
    2020-12-16 12:19

    It is normal. SQL Server does it in the same way. In SQL Server you can use

    SELECT * FROM table WHERE ISNULL(avalue, 0) <> 1
    

    For postgresql equivalent watch this: What is the PostgreSQL equivalent for ISNULL()

    Consider to use NOT NULL column specification with default value, if it makes sense.

    EDIT:

    I think it is logic. NULL is not a value, so it is excluded from searching - you have to specify it explicitly. If SQL designers decides to go by second way (include nulls automatically), then you would get more troubles if you need to recognize no values

提交回复
热议问题