sqlstreak

Original study

PostgreSQL vs SQLite: what differs, measured on 240 real queries

PostgreSQL 18.6 (PGlite 0.5.16) and SQLite 3.54.1 · measured · recomputed on every release

Short answer

Of 240 graded queries in a beginner-to-advanced SQL course, 28 (11.7%) needed different SQL in PostgreSQL and SQLite, almost all of them because of dates. The other 212 ran unchanged on both, and the results matched, apart from formatting such as true versus 1.

240

graded queries, each run on both engines

11.7%

needed different SQL

57 of 85

function edge cases behave the same

15 of 42

beginner mistakes only PostgreSQL reports

How we measured

sqlstreak's course has 240 graded query exercises across 16 units, from a first SELECT to window functions, recursive queries and analytics. Every exercise has an official solution, and every solution is executed on both engines each time the site is built; a build fails if the two engines disagree.

When a solution couldn't be written once for both, the course stores one per engine. Counting those, and comparing the raw rows each engine returns for the shared ones, gives the numbers on this page. They are recomputed from scratch on every release, with the engine versions shown above.

Caveats: this is one course's queries on three small sample databases, not a survey of every feature. It shows what a learner meets on the way from SELECT to window functions.

Which queries needed different SQL

What differedQueriesUnits
Dates and times24Text and dates, Recursive queries, Analytics patterns, Interview pack
ROLLUP subtotals3Advanced windows
Text functions1Text and dates
Dates and times: one example (dt-2)

PostgreSQL

SELECT name, EXTRACT(YEAR FROM arrived_on) AS arrival_year FROM pets;

SQLite

SELECT name, strftime('%Y', arrived_on) AS arrival_year FROM pets;
ROLLUP subtotals: one example (bs-6)

PostgreSQL

SELECT status, COUNT(*) AS orders FROM orders GROUP BY ROLLUP(status);

SQLite

SELECT status, COUNT(*) AS orders FROM orders GROUP BY status UNION ALL SELECT NULL, COUNT(*) FROM orders;
Text functions: one example (tx-5)

PostgreSQL

SELECT split_part(name, ' ', 1) AS first_name FROM customers;

SQLite

SELECT substr(name, 1, instr(name, ' ') - 1) AS first_name FROM customers;

The teaching material shows the same pattern: 16 of the course's 146 lesson examples and 13 of the 102 guide examples are written once per engine. The rest run unchanged on both.

When the SQL was the same, were the results?

For the 212 queries that ran unchanged, the course's grader accepted both engines' results every time. Byte for byte, this is how they compared:

Raw resultsQueries
Byte-for-byte identical147
Same rows, different order (the query had no ORDER BY, so both orders are correct)54
true/false in PostgreSQL, 1/0 in SQLite9
The same number to six decimal places, different floating-point digits2

Function edge cases

The function reference runs tricky inputs through both engines. Of 85 cases that exist in both, 28 return something different:

Mistakes only PostgreSQL reports

Of 42 common beginner mistakes, 15 raise an error in PostgreSQL but run in SQLite, usually returning something plausible and wrong. Code tested only on SQLite can carry these bugs for a long time.

The raw data

One row per query, with both solutions where they differ. Free to reuse under CC BY 4.0 with a link to this page.

Side by side

Try both engines