If else with 5 possible cases PostgreSQL I have bunch of records in Database and i have been searching for query on NULL json object and i got that right,but now its difficult for me to continue it on 5 possible cases

For example: am showing data on basis of 5 cases and 3 attributes

config-&gt;'external_http_port' , config-&gt;'external_host' , config-&gt;'snapshots'-&gt;&gt;'jpg'


cases are

1: config-&gt;'external_http_port' can be null

2: config-&gt;'external_host' can be null

3: config-&gt;'snapshots'-&gt;&gt;'jpg' can be null

4: All three can be null

5: two of three can be null.

for just checking all three nulls i am doing query as 

select * from cameras where (config-&gt;'external_http_port') is null and (config-&gt;'external_host') is null and (config-&gt;'snapshots'-&gt;&gt;'jpg') is null


any help will be appreciated 

Using PostgreSQL 9.3
Despite the long comments, it's still not clear if you need one query for each case or a single query that includes all five of them. So, we'll take them separately:


config-&gt;'external_http_port' is null

select * from cameras 
where config-&gt;'external_http_port' is null ;

config-&gt;'external_host' is null
(omitting the select):

where config-&gt;'external_host' is null ;

config-&gt;'snapshots'-&gt;&gt;'jpg' is null

where config-&gt;'snapshots'-&gt;&gt;'jpg' is null ;

all three are null (you got that right!):

where config-&gt;'external_http_port' is null 
  and config-&gt;'external_host' is null 
  and config-&gt;'snapshots'-&gt;&gt;'jpg' is null ;

two out of three are are null (and the third isn't)

where (config-&gt;'external_http_port' is null)::int
      + (config-&gt;'external_host' is null)::int 
      + (config-&gt;'snapshots'-&gt;&gt;'jpg' is null)::int 
      = 2 ;



And if you want all five cases in one query, i.e. any of the five conditions to hold, this can be written (using a complicated condition, similar to the 5th case above):

    where (config-&gt;'external_http_port' is null)::int
          + (config-&gt;'external_host' is null)::int 
          + (config-&gt;'snapshots'-&gt;&gt;'jpg' is null)::int 
          &gt;= 1 ;


or more simply:

    where config-&gt;'external_http_port' is null 
       or config-&gt;'external_host' is null 
       or config-&gt;'snapshots'-&gt;&gt;'jpg' is null ;