Dialect Differences Cheat Sheet

Updated · 12 min read
mediumPostgreSQL 18sqldialectsmysqlsql-serveroraclesqlitems-accesscheat-sheetinterview

The same SQL task can be written differently in each database, and, more surprisingly, the same SQL can behave differently. LIMIT 2 versus TOP 2 is easy to spot: the query simply fails on the wrong database. The quieter differences are the dangerous ones. 7 / 2 is 3 in PostgreSQL and 3.5 in MySQL, and 'navika' LIKE 'Navika' is false in PostgreSQL but true in SQLite. In Oracle, an empty string is NULL. This cheat sheet compares six databases: PostgreSQL, MySQL, SQL Server, SQLite, Oracle and MS Access (legacy). Each row is marked standard when the SQL standard defines the form, or dialect when it doesn't. PostgreSQL examples run in Try it; SQLite results come from the sqlite3 shell, version 3.54; the other columns show syntax from each database's documentation.

In One Minute

  • Syntax differs most for limiting rows, ids, text joining, dates, upserts and quoting names.
  • Behavior differs for integer division, case sensitivity, NULL in unique columns, empty strings, transactional DDL and default isolation.
  • SQLite accepts almost any value in any column unless the table is STRICT.
  • Oracle treats '' as NULL; SQL Server allows only one NULL in a unique column.
  • MySQL and SQL Server compare text case-insensitively by default; PostgreSQL and Oracle don't.
  • When moving SQL between databases, test the behavior, not only the syntax.

Syntax: Common Tasks

TaskPostgreSQLMySQLSQL ServerSQLiteOracleMS Access
First 10 rowsLIMIT 10 or FETCH FIRST 10 ROWS ONLY (standard)LIMIT 10TOP 10, or OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLYLIMIT 10FETCH FIRST 10 ROWS ONLY (12c+)TOP 10
Skip 20, take 10OFFSET 20 LIMIT 10LIMIT 20, 10 or LIMIT 10 OFFSET 20OFFSET 20 ROWS FETCH NEXT 10 ROWS ONLYLIMIT 10 OFFSET 20OFFSET 20 ROWS FETCH NEXT 10 ROWS ONLYNo direct form
Join texta || b (standard), concat()CONCAT(a, b)a + b, CONCAT()a || ba || b, CONCAT(a, b) (two args)a & b
Auto-numbered idGENERATED ALWAYS AS IDENTITY (standard), SERIALAUTO_INCREMENTIDENTITY(1, 1)INTEGER PRIMARY KEYGENERATED AS IDENTITY (12c+)AUTOINCREMENT / AutoNumber
Quote a name"name" (standard)`name`[name] or "name""name""name"[name]
Replace NULLCOALESCE (standard)COALESCE, IFNULLCOALESCE, ISNULLCOALESCE, IFNULLCOALESCE, NVLNz()
If / elseCASE (standard)CASE, IF()CASE, IIF()CASE, iif()CASE, DECODE()IIf()
NowCURRENT_TIMESTAMP (standard), now()NOW()SYSDATETIME(), GETDATE()datetime('now')SYSTIMESTAMP, SYSDATENow()
Add 30 daysd + 30, d + INTERVAL '30 days'DATE_ADD(d, INTERVAL 30 DAY)DATEADD(day, 30, d)date(d, '+30 days')d + 30DateAdd("d", 30, d)
BooleansBOOLEAN (standard)BOOLEAN (stored as TINYINT(1))BIT0 / 1 integersBOOLEAN (23ai), NUMBER(1) beforeYes/No
UpsertINSERT ... ON CONFLICT, MERGE (standard, 15+)INSERT ... ON DUPLICATE KEY UPDATEMERGEINSERT ... ON CONFLICTMERGENo
Read a JSON fielddata ->> 'name', JSON_VALUEdata ->> '$.name', JSON_VALUEJSON_VALUE(data, '$.name')data ->> '$.name'JSON_VALUE(data, '$.name')No
Procedural languagePL/pgSQLSQL/PSM-style proceduresT-SQLNone (use triggers or the app)PL/SQLVBA

Check versions before relying on a row. Many of these arrived recently: FETCH FIRST in Oracle 12c, MERGE in PostgreSQL 15, ->> in SQLite 3.38, BOOLEAN in Oracle Database 23ai. The SQL Syntax by Database reference has copy-ready versions of each.

One task, six syntaxes; PostgreSQL and SQLite results are real

Behavior: Same SQL, Different Results

These are the differences that don't produce an error: the query runs everywhere, and the answers differ. Here is a small script run on PostgreSQL:

SQL▶ Try it
SELECT 7 / 2 AS int_div, 7 / 2.0 AS dec_div;
 
SELECT 'navika' LIKE 'Navika' AS like_ignores_case,
       'navika' = 'Navika'    AS equals;
 
CREATE TABLE t (n INTEGER, email TEXT UNIQUE);
INSERT INTO t VALUES ('abc', NULL);
INSERT INTO t VALUES (5, NULL);
INSERT INTO t VALUES (6, NULL);
SELECT n, email FROM t ORDER BY n;
Output
 int_div |      dec_div
---------+--------------------
       3 | 3.5000000000000000
(1 row)
 
 like_ignores_case | equals
-------------------+--------
 f                 | f
(1 row)
 
CREATE TABLE
 
ERROR:  invalid input syntax for type integer: "abc"
 
INSERT 0 1
 
INSERT 0 1
 
 n | email
---+-------
 5 | NULL
 6 | NULL
(2 rows)

And nearly the same script in SQLite 3.54, run with sqlite3 -header -column (with typeof() added to show how each value was stored):

SQL
SELECT 7 / 2 AS int_div, 7 / 2.0 AS dec_div;
SELECT 'navika' LIKE 'Navika' AS like_ignores_case,
       'navika' = 'Navika'    AS equals;
CREATE TABLE t (n INTEGER, email TEXT UNIQUE);
INSERT INTO t VALUES ('abc', NULL);
INSERT INTO t VALUES (5, NULL);
SELECT n, typeof(n) AS stored_as, email FROM t;
Output
int_div  dec_div
-------  -------
      3      3.5
like_ignores_case  equals
-----------------  ------
                1       0
 n   stored_as  email
---  ---------  -----
abc  text
  5  integer

Explanation:

  • Integer division: both print 3 for 7 / 2, because both integers stay integers. MySQL and Oracle would give 3.5000 and 3.5. Write 7 / 2.0 or CAST(7 AS NUMERIC) / 2 when you want the fraction everywhere.
  • LIKE and case: PostgreSQL's LIKE is case-sensitive, so 'navika' LIKE 'Navika' is false (f). SQLite's LIKE ignores case for plain ASCII letters, so it's true (1). Plain = is case-sensitive in both.
  • Types: PostgreSQL refuses 'abc' for an INTEGER column. SQLite stores it anyway, as text, because SQLite columns have a type affinity, not a strict type. A table declared STRICT (SQLite 3.37 and later) refuses it.
  • NULL in a unique column: both allow several NULL emails, because NULL isn't equal to NULL.
Real results: PostgreSQL and SQLite disagree on LIKE and on types

Behavior Across All Six

BehaviorPostgreSQLMySQLSQL ServerSQLiteOracleMS Access
7 / 233.5000333.53.5
= on text, default setupCase-sensitiveCase-insensitive (default collation)Case-insensitive (default collation)Case-sensitiveCase-sensitiveCase-insensitive
'' (empty string)A valueA valueA valueA valueSame as NULLA value (when allowed)
Several NULLs in a UNIQUE columnAllowed (unless NULLS NOT DISTINCT)AllowedOnly one (use a filtered unique index for more)AllowedAllowedDepends on the index's Ignore Nulls setting
CREATE TABLE inside a transaction can roll backYesNo: DDL commits automaticallyYesYesNo: DDL commits automaticallyNot offered in the query editor
Default isolation levelRead CommittedRepeatable Read (InnoDB)Read Committed (with row versioning by default in Azure SQL Database)SerializableRead CommittedNot applicable
Primary key clusters the tableNo (heap table)Yes (InnoDB)Yes, by defaultRowid tables cluster on the rowidNo (unless index-organized)Not applicable
Time zonesTIMESTAMPTZ stores a momentTIMESTAMP converts to UTC; DATETIME doesn'tDATETIMEOFFSETText or numbers; no date typeTIMESTAMP WITH TIME ZONENone

The four that cause the most bugs when moving between databases:

  1. Case sensitivity. A login check WHERE email = 'Navika@Example.com' matches navika@example.com on MySQL and SQL Server defaults, but not on PostgreSQL. On PostgreSQL, compare lower(email), use the citext extension, or a case-insensitive collation.
  2. Oracle's empty string. WHERE middle_name = '' never matches in Oracle, because '' is NULL. Use IS NULL.
  3. SQL Server's single NULL. A UNIQUE email column refuses the second student with no email. Use a filtered index: CREATE UNIQUE INDEX ... WHERE email IS NOT NULL.
  4. Non-transactional DDL in MySQL and Oracle. A failing migration can leave its first steps applied (Schema Migrations).
Four behaviors that change answers when SQL moves between databases

Checking Which Database You're On

When in doubt, ask the database for its name and version:

DatabaseQuery
PostgreSQLSELECT version(); or SHOW server_version;
MySQL / MariaDBSELECT VERSION();
SQL ServerSELECT @@VERSION;
SQLiteSELECT sqlite_version();
OracleSELECT banner FROM v$version;
SQL▶ Try it
SHOW server_version;
Output
 server_version
----------------
 18.7
(1 row)

MariaDB and Db2

MariaDB started as a copy (fork) of MySQL in 2009 and is still close to it: the MySQL column above mostly applies. The two have drifted in newer features; for example, MariaDB has system-versioned (temporal) tables and RETURNING on INSERT and DELETE, while MySQL has neither, and their JSON implementations differ. IBM Db2 follows the standard closely: FETCH FIRST, ||, GENERATED AS IDENTITY, MERGE and SQL PL procedures.

MS Access Functions (Legacy)

MS Access uses its own function names, closer to Visual Basic than to SQL. If you meet an old Access database:

NeedAccessStandard / PostgreSQL
Replace NULLNz(x, 0)COALESCE(x, 0)
If / elseIIf(cond, a, b)CASE WHEN cond THEN a ELSE b END
Join texta & ba || b
Text patternLIKE "Nav*"LIKE 'Nav%'
TodayDate()CURRENT_DATE
Part of a dateYear(d), Month(d), DatePart("q", d)EXTRACT(YEAR FROM d)
FormatFormat(d, "yyyy-mm-dd")to_char(d, 'YYYY-MM-DD')

Access uses * and ? as wildcards in its own query editor (and % and _ in ANSI-92 mode), #2025-12-03# for date literals, and double quotes for text.

Common Mistakes

Testing on one database and deploying on another. The syntax may match while the answers don't. Test on the engine you'll run.

Relying on case-insensitive comparisons. They are a collation setting, not SQL. Normalize case explicitly when it matters.

Using '' and NULL interchangeably. Oracle treats them as the same; nobody else does.

Integer division surprises. count(*) / 3 loses the fraction in PostgreSQL, SQL Server and SQLite. Cast first.

Assuming DDL rolls back. MySQL and Oracle commit CREATE, ALTER and DROP immediately.

Interview Corner

What does SELECT 7 / 2 return?

It depends on the database: 3 in PostgreSQL, SQL Server and SQLite, which keep integer division; 3.5000 in MySQL and 3.5 in Oracle. Cast one side to a decimal type to get the fraction everywhere.

How does Oracle treat an empty string?

As NULL. '' IS NULL is true in Oracle, so WHERE col = '' never matches. Other major databases treat '' as a real, empty value.

How do NULLs behave in a UNIQUE column?

Most databases allow many NULLs because NULL isn't equal to NULL. SQL Server allows only one unless you use a filtered unique index; PostgreSQL 15+ can refuse duplicates with NULLS NOT DISTINCT.

Is text comparison case-sensitive?

It depends on the collation. PostgreSQL and Oracle are case-sensitive by default; MySQL and SQL Server defaults are case-insensitive. SQLite's = is case-sensitive, but its LIKE ignores ASCII case.

Practice

Challenge: Make a case-insensitive search that gives the same answer on every database: find students whose first name is 'navika', however it was typed, using only standard SQL.

Show solution
SQL▶ Try it
SELECT student_id, first_name
FROM students
WHERE LOWER(first_name) = LOWER('navika')
ORDER BY student_id;
Output
 student_id | first_name
------------+------------
        103 | Navika
(1 row)

Lowercasing both sides makes the comparison independent of the database's collation, so it returns Navika on PostgreSQL, MySQL, SQL Server, SQLite and Oracle alike. On a big table, it needs an index on LOWER(first_name) to stay fast (Index Design).

Quick check: Dialect differences

4 questions
1Which database treats '' (an empty string) as NULL?
2'navika' LIKE 'Navika' is true in which database?
3Where can a failed migration leave a CREATE TABLE behind even inside a transaction?
4A UNIQUE email column refuses a second NULL email. Which database is it likely to be?

Key Takeaways

You want toPortable choice
Limit rowsFETCH FIRST n ROWS ONLY (or your database's form)
Case-insensitive matchLOWER(col) = LOWER(value)
Decimal divisionCAST(a AS NUMERIC) / b
Replace NULLCOALESCE(a, b)
Check for "no value"IS NULL (never = '' in Oracle)

Was this tutorial helpful?

Lesson 108 of 115