0
0
PostgreSQLquery~10 mins

Standard comparison operators in PostgreSQL - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Standard comparison operators
Start Query
Evaluate Left Operand
Evaluate Right Operand
Apply Comparison Operator
Result: TRUE / FALSE / NULL
Use Result in WHERE or Condition
The database evaluates both sides of the comparison, applies the operator, and returns TRUE, FALSE, or NULL to filter or decide query results.
Execution Sample
PostgreSQL
SELECT * FROM employees WHERE salary > 50000;
This query selects employees whose salary is greater than 50000.
Execution Table
StepLeft OperandOperatorRight OperandEvaluationResult
1salary = 45000>5000045000 > 50000FALSE
2salary = 52000>5000052000 > 50000TRUE
3salary = 50000>5000050000 > 50000FALSE
4salary = NULL>50000NULL > 50000NULL
5End of rowsQuery returns rows where result is TRUE
💡 All rows evaluated; only rows with TRUE result are returned.
Variable Tracker
VariableStartAfter 1After 2After 3After 4Final
salaryN/A450005200050000NULLN/A
comparison_resultN/AFALSETRUEFALSENULLN/A
Key Moments - 2 Insights
Why does the comparison with NULL not return TRUE or FALSE?
In row 4 of the execution_table, comparing salary NULL with 50000 results in NULL because NULL means unknown, so the comparison cannot be TRUE or FALSE.
Why is salary = 50000 > 50000 FALSE and not TRUE?
In row 3, the operator '>' means strictly greater than, so 50000 > 50000 is FALSE because they are equal, not greater.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the result of comparing salary = 52000 with 50000 using '>'?
ATRUE
BFALSE
CNULL
DError
💡 Hint
Check row 2 in the execution_table where salary is 52000.
At which step does the comparison result become NULL?
AStep 1
BStep 4
CStep 2
DStep 3
💡 Hint
Look for the row with salary NULL in the execution_table.
If the operator was changed from '>' to '>=' at step 3, what would be the result?
AFALSE
BNULL
CTRUE
DError
💡 Hint
Consider that '>=' means greater than or equal, check step 3 where salary equals 50000.
Concept Snapshot
Standard comparison operators compare two values.
Common operators: =, <>, >, <, >=, <=.
Return TRUE, FALSE, or NULL (unknown).
Used in WHERE clauses to filter rows.
NULL comparisons yield NULL, not TRUE or FALSE.
Full Transcript
This visual execution shows how standard comparison operators work in PostgreSQL. The query selects employees with salary greater than 50000. Each row's salary is compared to 50000 using the '>' operator. The result is TRUE if salary is greater, FALSE if not, and NULL if salary is unknown (NULL). Only rows with TRUE results are returned. Important points include that NULL comparisons do not return TRUE or FALSE, and that '>' means strictly greater than, so equal values return FALSE.