Home > Software design >  SQL Boolean Column Default Value
SQL Boolean Column Default Value

Time:12-21

Someone gave me this code:

select * from table where is_active

Is the is_active column, despite not having been set to anything, set to TRUE by default? Does the above query mean this:

select * from table where is_active = TRUE

It appears so, but couldn't find anything in the PostgreSQL documentation, so just wanted to confirm.

CodePudding user response:

Yes. You are right here. When the system looks at this query select * from table_name where col1>col2, it tries to find effective boolean expression after where clause, and ends up evaluating the expression to either true or false. But since the column value is already boolean so there is no need for that. select * from table where is_active is infact better. This is true for all SQL languages

  • Related