0

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.

4
  • 2
    both queries will return the same result. All expressions in the where will be checked if they're true :) Commented Dec 20, 2022 at 15:37
  • 3
    where clause expects a boolean (logical) expression. is_active is one itself. is_active = TRUE is the same but more or less a tautalogy. Same with not is_active and is_active = FALSE Commented Dec 20, 2022 at 15:37
  • It's here in the PostgreSQL docs: where condition is any expression that evaluates to a result of type boolean. .... see: link Commented Dec 20, 2022 at 17:30
  • Yes, but I was expecting "is_active = True" not just the column by itself. Commented Dec 20, 2022 at 18:04

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.