Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shortcut for checking boolean false value

In java the following works:

boolean varBoo = true;

if(varBoo) means: if(varBoo = true) and

if(!varBoo) means: if(varBoo = false)

Im working on a postgreSQL statement right now, which looks like this:

CASE
  WHEN varInt < XX AND varBoo THEN 1.0    -- Short for varBoo = TRUE
  WHEN varInt < XX AND varBoo = FALSE THEN 0.5
END

Is there any way to write varBoo = FALSE shorter in PostgreSQL?

java equivalent would be !varBoo.

like image 923
Koen Avatar asked Jun 20 '15 22:06

Koen


People also ask

How do you check if a boolean is true or false?

An alternative approach is to use the logical OR (||) operator. To check if a value is of boolean type, check if the value is equal to false or equal to true , e.g. if (variable === true || variable === false) . Boolean values can only be true and false , so if either condition is met, the value has a type of boolean.

How do you know if a boolean is a value or not?

Syntax. Follow the below syntax to check for Boolean type variable using strict equality operator. If( variable === true || variable === false ) { // variable is of Boolean type. }

What is the boolean value for false?

Boolean values and operations Constant true is 1 and constant false is 0. It is considered good practice, though, to write true and false in your program for boolean values rather than 1 and 0.

How do you set a boolean to a false value?

To initialize or assign a true or false value to a Boolean variable, we use the keywords true and false. Boolean values are not actually stored in Boolean variables as the words “true” or “false”. Instead, they are stored as integers: true becomes the integer 1, and false becomes the integer 0.


1 Answers

You can try with not:

case
  when varInt < XX and varBoo then 1.0  
  when varInt < XX and not(varBoo) then 0.5
end
like image 124
potashin Avatar answered Sep 29 '22 09:09

potashin