Back to all posts

Comparison of WHERE Clause Operators in MSSQL vs PostgreSQL

Here's a comparison of how operators in the WHERE clause are used in Microsoft SQL Server (MSSQL) vs PostgreSQL : Operator Purpose Used in MSSQL Used in Po…

Here's a comparison of how operators in the WHERE clause are used in Microsoft SQL Server (MSSQL) vs PostgreSQL:

OperatorPurposeUsed in MSSQLUsed in PostgreSQLNotes
=Equal to✅ Yes✅ YesCommon in both
<Less than✅ Yes✅ YesCommon in both
>Greater than✅ Yes✅ YesCommon in both
<=Less than or equal to✅ Yes✅ YesCommon in both
>=Greater than or equal to✅ Yes✅ YesCommon in both
<>Not equal to✅ Yes✅ YesStandard SQL operator
!=Not equal to (alternate form)✅ Yes✅ YesSupported in both, though <> is standard
LIKEPattern matching (case-sensitive in both by default)✅ Yes✅ YesPostgreSQL is case-sensitive by default; use ILIKE for insensitive
ILIKEPattern matching (case-insensitive)❌ No✅ YesPostgreSQL-only
ANDLogical AND✅ Yes✅ YesCommon in both
ORLogical OR✅ Yes✅ YesCommon in both
INCheck if a value is in a list✅ Yes✅ YesCommon in both
BETWEENRange check (inclusive)✅ Yes✅ YesCommon in both
IS NULLChecks if a value is NULL✅ Yes✅ YesCommon in both
NOTLogical negation (NOT LIKE, NOT IN, etc.)✅ Yes✅ YesCommon in both

⚠️ Key Differences:

  • ILIKE is only available in PostgreSQL for case-insensitive pattern matching. In MSSQL, use LOWER(column) LIKE 'pattern' or COLLATE for case-insensitive searches.
  • Pattern matching behavior (LIKE) is case-insensitive by default in MSSQL depending on collation, but case-sensitive in PostgreSQL unless ILIKE is used.

✅ Example in MSSQL:

SQL
-- Case-sensitive search: Only matches names starting with lowercase 'e' (e.g., 'emily')
-- Even if the database or column is case-insensitive by default, we force case sensitivity using COLLATE
SELECT * FROM Employees
WHERE Department = 'HR' 
  AND Name COLLATE Latin1_General_CS_AS LIKE 'e%';

-- Default behavior (usually case-insensitive depending on collation)
-- This will match names starting with both 'E' and 'e' if the column uses a case-insensitive collation
SELECT * FROM Employees
WHERE Department = 'HR' 
  AND Name LIKE 'E%';

✅ Example in PostgreSQL:

SQL
-- Case-sensitive search: Matches names starting only with lowercase 'e'
-- PostgreSQL's LIKE is case-sensitive by default
SELECT * FROM Employees
WHERE Department = 'HR' 
  AND Name LIKE 'e%';

-- Case-insensitive search: Matches names starting with 'E' or 'e'
-- PostgreSQL's ILIKE operator performs case-insensitive pattern matching
SELECT * FROM Employees
WHERE Department = 'HR' 
  AND Name ILIKE 'E%';

Keep building your data skillset

Explore more SQL, Python, analytics, and engineering tutorials.