I am newbie in postgresql, Currently I am working on one project, my query works fine when values are available in column, but if values are not there I want to use 0 instead of it. How can we write validation in my query, can any one help me to solve this ?

select (to_char((myfirsthour) - ((mysecondhours) - ((mybreak+ myteabreak))),'FM99,999,999'))::character varying as mydaiywork

so here if I do not get values any one of column I want to use 0.

  • @LaurenzAlbe can you post it as full answer if possible Jun 29, 2020 at 13:00

1 Answer 1


Use coalesce (and forget the unnecessary cast to character varying):

SELECT coalesce(
             myfirsthour - mysecondhours + (mybreak + myteabreak),
       ) AS mydaiywork

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.