SQL Dialect Rosetta Stone: Oracle, PostgreSQL, MySQL & SQLite

Side-by-side verified SQL translations and subtle behavioral gotchas for engineers migrating between Oracle, PostgreSQL, MySQL, and SQLite.

Cross-Engine SQL Translations (12 Topics)

DML & Writes

UPSERT (MERGE INTO vs ON CONFLICT vs ON DUPLICATE KEY)

Atomic insert-or-update syntax differs sharply across Oracle, PostgreSQL, MySQL, and SQLite.

Hierarchy & Graphs

Hierarchical Queries (CONNECT BY PRIOR vs WITH RECURSIVE)

Translating legacy Oracle START WITH / CONNECT BY PRIOR trees into ANSI WITH RECURSIVE CTEs.

Pagination

Pagination & Top-N (ROWNUM / FETCH FIRST vs LIMIT OFFSET)

Safe Top-N and keyset pagination syntax across engines without falling into Oracle's ROWNUM ordering trap.

Expressions

NULL Coalescing (NVL / NVL2 vs COALESCE / IFNULL)

Subtle short-circuit evaluation and type coercion differences between Oracle NVL and ANSI COALESCE.

Data Types

Empty String '' vs NULL Trap (Oracle vs PostgreSQL / MySQL / SQLite)

The #1 silent bug during Oracle-to-PostgreSQL migrations: Oracle treats '' as NULL, whereas PostgreSQL, MySQL, and SQLite treat '' as a valid 0-length string.

Dates & Time

Date Truncation & Intervals (TRUNC / SYSDATE vs DATE_TRUNC / INTERVAL)

Index-friendly date truncation and interval math across all four SQL dialects.

Expressions

Conditional Logic (Oracle DECODE vs ANSI CASE WHEN)

Migrating Oracle DECODE() expressions to portable ANSI CASE WHEN without losing NULL equality semantics.

Aggregation

String Aggregation (LISTAGG vs STRING_AGG vs GROUP_CONCAT)

Concatenating grouped row values into a sorted delimited string across SQL engines.

DDL & Keys

Auto-Increment & Sequences (GENERATED AS IDENTITY vs SERIAL vs AUTO_INCREMENT)

Modern primary key generation syntax across Oracle 12c+, PostgreSQL 10+, MySQL 8, and SQLite.

DML & Writes

Returning Inserted/Updated Rows (RETURNING INTO vs RETURNING)

Fetching generated IDs or updated values in a single round-trip without a second SELECT.

Pattern Matching

Regular Expressions in SQL (REGEXP_LIKE vs ~ vs REGEXP)

POSIX regex matching operators and index behavior across SQL engines (pair with mcregex.com to audit ReDoS safety).

Query Tuning

CTE Optimization & Materialization (MATERIALIZE Hint vs AS MATERIALIZED)

Controlling whether Common Table Expressions are inlined (predicate pushdown) or materialized once.