E
E
EvgMul2017-04-26 14:03:05
PostgreSQL
EvgMul, 2017-04-26 14:03:05

How to correctly write a comparison condition in a query?

Hello.
I need to get data by condition. The field must equal the specified variable.
The problem is that the field can be null. Even if you assign null to the variable, the query does not work.

select house_id
          into   l_house_id
          from   houses_all
        where  houses_all.corp = l_corp

If houses_all.corp is not null, then the comparison will work, but if it's null, even if l_corp is also null, the query will return nothing. IS NULL won't work for me in this case.
Please tell me how can I solve this problem?
Thanks in advance to all who respond.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
gill-sama, 2017-04-26
@EvgMul

select house_id
          into   l_house_id
          from   houses_all
        where  COALESCE(houses_all.corp,'somevalue') = COALESCE(l_corp,'somevalue')

you can read here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question