Full answer
The question has three parts, and the answer differs for each.
Keywords such as select and SELECT mean the same thing everywhere.
Unquoted identifiers are case-insensitive. PostgreSQL does this by folding them to lower case, so Employees and employees are the same table. Quoting an identifier keeps its exact case: "Employees" in PostgreSQL is a different name from employees.
The data is where engines differ. On SQLite, = is case-sensitive but LIKE ignores case for ASCII letters:
CREATE TABLE departments (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL
);
CREATE TABLE employees (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
dept_id INTEGER REFERENCES departments(id),
manager_id INTEGER REFERENCES employees(id),
salary INTEGER,
hire_date TEXT
);
INSERT INTO departments VALUES (1,'Engineering'),(2,'Sales'),(3,'Support'),(4,'Legal');
INSERT INTO employees VALUES
(1,'Asha', 1,NULL,120000,'2019-03-01'),
(2,'Ravi', 1,1, 95000,'2020-07-15'),
(3,'Mei', 1,1, 95000,'2021-01-10'),
(4,'Tom', 2,1, 70000,'2022-05-20'),
(5,'Sara', 2,4, 62000,'2023-02-01'),
(6,'Diego',3,1, 55000,'2021-11-30'),
(7,'Lena', NULL,4, NULL, '2024-06-03'),
(8,'Omar', 3,6, 48000,'2024-09-09');SELECT
(SELECT COUNT(*) FROM employees WHERE name = 'asha') AS eq_lower,
(SELECT COUNT(*) FROM employees WHERE name LIKE 'asha') AS like_lower;| eq_lower | like_lower |
|---|---|
| 0 | 1 |
PostgreSQL treats both as case-sensitive, and offers ILIKE for a case-insensitive match:
SELECT
(SELECT COUNT(*) FROM employees WHERE name = 'asha') AS eq_lower,
(SELECT COUNT(*) FROM employees WHERE name LIKE 'asha') AS like_lower,
(SELECT COUNT(*) FROM employees WHERE name ILIKE 'asha') AS ilike_lower;| eq_lower | like_lower | ilike_lower |
|---|---|---|
| 0 | 0 | 1 |
For portable case-insensitive matching, compare lower-cased values: LOWER(name) = LOWER('asha'). Be aware this can stop a plain index on name from being used. PostgreSQL can index the expression LOWER(name), and SQLite can declare a column COLLATE NOCASE.
MySQL's default collations are case-insensitive, so 'asha' = 'Asha' is true there. That comes from the MySQL documentation and was not run here.
CREATE TABLE departments (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL
);
CREATE TABLE employees (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
dept_id INTEGER REFERENCES departments(id),
manager_id INTEGER REFERENCES employees(id),
salary INTEGER,
hire_date TEXT
);
INSERT INTO departments VALUES (1,'Engineering'),(2,'Sales'),(3,'Support'),(4,'Legal');
INSERT INTO employees VALUES
(1,'Asha', 1,NULL,120000,'2019-03-01'),
(2,'Ravi', 1,1, 95000,'2020-07-15'),
(3,'Mei', 1,1, 95000,'2021-01-10'),
(4,'Tom', 2,1, 70000,'2022-05-20'),
(5,'Sara', 2,4, 62000,'2023-02-01'),
(6,'Diego',3,1, 55000,'2021-11-30'),
(7,'Lena', NULL,4, NULL, '2024-06-03'),
(8,'Omar', 3,6, 48000,'2024-09-09');
SELECT
(SELECT COUNT(*) FROM employees WHERE name = 'asha') AS eq_lower,
(SELECT COUNT(*) FROM employees WHERE name LIKE 'asha') AS like_lower;Checked on SQLite 3.46.1, run twice with identical output. PostgreSQL results in the answer were checked on PostgreSQL 17.12.
Key points
- Keywords: never case-sensitive
- Unquoted identifiers: case-insensitive; PostgreSQL folds them to lower case
- Data: depends on engine and collation
- SQLite LIKE ignores ASCII case; PostgreSQL LIKE does not; ILIKE does
Common mistakes
- Creating a PostgreSQL table with a quoted mixed-case name and then querying it unquoted
- Wrapping an indexed column in LOWER() and losing the index
Follow-ups
- How would you make a case-insensitive unique constraint on email?
- What is a collation?
Tips
- Split the answer into keywords, identifiers and data; it shows structured thinking