IN Clause with NULL or IS NULL

后端 未结 7 1590
我在风中等你
我在风中等你 2020-11-30 00:26

Postgres is the database

Can I use a NULL value for a IN clause? example:

SELECT *
FROM tbl_name
WHERE id_field IN (\'value1\', \'value2\', \'value3\         


        
7条回答
  •  孤独总比滥情好
    2020-11-30 01:02

    An in statement will be parsed identically to field=val1 or field=val2 or field=val3. Putting a null in there will boil down to field=null which won't work.

    (Comment by Marc B)

    I would do this for clairity

    SELECT *
    FROM tbl_name
    WHERE 
    (id_field IN ('value1', 'value2', 'value3') OR id_field IS NULL)
    

提交回复
热议问题