The SQL Standard and Dialects
SQL is an international standard, ISO/IEC 9075, and every major relational database implements a large part of it, plus its own additions, called its dialect. The standard is why a SELECT with a WHERE, a JOIN and a GROUP BY that you learned on PostgreSQL also runs on MySQL, SQL Server, Oracle and SQLite. The dialects are why limiting rows, joining text or generating ids can look different on each one. In this lesson, we will see how the standard grew from SQL-86 to SQL:2023, what it does and doesn't cover, why databases add their own features, and how to tell standard SQL from dialect SQL so you can write queries that move between databases with little change.
In One Minute
- The SQL standard is ISO/IEC 9075, published by ISO and IEC and revised many times: SQL-86 to SQL:2023.
- It defines the language: queries, data types, constraints, transactions, privileges and much more.
- No database implements all of it, and every database adds extras. That combination is its dialect.
- Core SQL (
SELECT, joins,GROUP BY,INSERT,UPDATE,DELETE,CREATE TABLE) is very similar everywhere. - Differences show up most in limiting rows, text and date functions, ids, upserts, JSON and procedural code.
- Prefer the standard form when your database supports it; use the dialect form when it's clearly better, and know which is which.
How the Standard Grew
SQL started at IBM in the 1970s as SEQUEL, a language for its System R research database, and became a standard in 1986. Each revision since has added features that databases had already started to offer:
| Version | Notable additions |
|---|---|
| SQL-86 / SQL-89 | The first standard: SELECT, INSERT, UPDATE, DELETE, basic CREATE TABLE, then integrity constraints |
| SQL-92 | A big expansion: JOIN ... ON syntax, outer joins, CASE, CAST, DATE and TIMESTAMP types, schema changes with ALTER |
| SQL:1999 | Recursive queries (WITH RECURSIVE), triggers, the BOOLEAN type, roles, procedural SQL (SQL/PSM) |
| SQL:2003 | Window functions, MERGE, identity columns, sequences, XML |
| SQL:2006 | More XML features (XQuery) |
| SQL:2008 | FETCH FIRST, OFFSET, TRUNCATE, INSTEAD OF triggers |
| SQL:2011 | Temporal tables: rows that remember when they were valid (system versioning) |
| SQL:2016 | JSON functions, row pattern recognition (MATCH_RECOGNIZE), LISTAGG |
| SQL:2019 | Multidimensional arrays (a separate part, SQL/MDA) |
| SQL:2023 | Property graph queries (SQL/PGQ), a JSON data type, ANY_VALUE, GREATEST and LEAST, UNIQUE NULLS DISTINCT, underscores in numbers |
The standard is large: it is split into many parts, such as Part 2 "Foundation" (the core language), Part 4 for procedural SQL, Part 9 for external data, Part 14 for XML, and Part 16 for property graphs. ISO sells it rather than publishing it for free, which is one reason most developers learn SQL from their database's own documentation instead.
Standard and Dialect, Side by Side
Many tasks can be written in standard SQL or in a database's own shorter form, and PostgreSQL accepts both. Here are three pairs:
-- Limit rows: standard (SQL:2008) and the common LIMIT
SELECT title FROM courses ORDER BY course_id FETCH FIRST 2 ROWS ONLY;
SELECT title FROM courses ORDER BY course_id LIMIT 2;
-- Convert a type: standard CAST and PostgreSQL's :: shorthand
SELECT CAST('2025-12-03' AS DATE) + 30 AS standard,
'2025-12-03'::date + 30 AS postgres_only;
-- Join text: standard || and the widely supported concat()
SELECT first_name || ' ' || last_name AS standard,
concat(first_name, ' ', last_name) AS function_form
FROM students WHERE student_id = 103; title
-------------
Java Basics
Java OOP
(2 rows)
title
-------------
Java Basics
Java OOP
(2 rows)
standard | postgres_only
------------+---------------
2026-01-02 | 2026-01-02
(1 row)
standard | function_form
------------------+------------------
Navika Anamaneni | Navika Anamaneni
(1 row)Explanation: Each pair gives the same result on PostgreSQL. The difference is where else it runs:
| Task | Standard form | Where it runs | Dialect forms |
|---|---|---|---|
| First 2 rows | FETCH FIRST 2 ROWS ONLY | PostgreSQL, Oracle 12c and later, Db2, SQL Server (as OFFSET 0 ROWS FETCH NEXT 2 ROWS ONLY, with ORDER BY) | LIMIT 2 (PostgreSQL, MySQL, SQLite); TOP 2 (SQL Server, Access) |
| Convert a type | CAST(x AS DATE) | All major databases except MS Access | x::date (PostgreSQL); CONVERT(DATE, x) (SQL Server) |
| Join text | a || b | PostgreSQL, Oracle, SQLite, Db2 | CONCAT(a, b) (most); a + b (SQL Server); a & b (Access). In MySQL, || means OR unless the PIPES_AS_CONCAT mode is on |
concat() isn't in the standard, but it's in almost every database, which makes it a practical portable choice. Portability is about where your SQL must run, not only about what the standard says.
Why Every Database Has a Dialect
Databases add features faster than the standard can describe them, and some compete on those features. Four reasons explain most differences:
| Reason | Example |
|---|---|
| The feature came before the standard | LIMIT and TOP existed long before SQL:2008 added FETCH FIRST; many people still prefer them |
| The standard leaves details to each database | Default isolation level, how text sorts, the maximum length of a name |
| A database's own design | PostgreSQL's arrays and :: casts; SQL Server's IDENTITY and T-SQL; Oracle's PL/SQL |
| Backward compatibility | MySQL keeps || as OR so old applications still work |
Procedural code differs the most. The standard's SQL/PSM language is close to MySQL's and Db2's stored procedures, but PostgreSQL uses PL/pgSQL, SQL Server uses T-SQL and Oracle uses PL/SQL, and code in one rarely runs on another without changes (Stored Procedures).
Newer Standard Features in PostgreSQL
Recent PostgreSQL versions have added many SQL:2016 and SQL:2023 features. All of these run on PostgreSQL 16 or later (the JSON_TABLE function needs 17):
SELECT 1_000_000 AS underscores_in_numbers,
0x1F AS hex_literal,
greatest(3, 7, 5) AS greatest_value;
SELECT '{"a": 1}' IS JSON AS valid_json,
'not json' IS JSON AS invalid_json;
SELECT *
FROM JSON_TABLE(
'[{"name": "Navika", "city": "Dallas"},
{"name": "Srihitha", "city": "San Francisco"}]',
'$[*]' COLUMNS (name TEXT PATH '$.name', city TEXT PATH '$.city')
) AS people
ORDER BY name; underscores_in_numbers | hex_literal | greatest_value
------------------------+-------------+----------------
1000000 | 31 | 7
(1 row)
valid_json | invalid_json
------------+--------------
t | f
(1 row)
name | city
----------+---------------
Navika | Dallas
Srihitha | San Francisco
(2 rows)Explanation: SQL:2023 allows underscores in number literals for readability and hexadecimal literals such as 0x1F (31); GREATEST and LEAST were common extensions that SQL:2023 finally standardized. IS JSON (SQL:2016) checks whether text is valid JSON, and JSON_TABLE (SQL:2016) turns a JSON array into rows and columns (JSON in SQL). Support differs across databases: Oracle and MySQL have JSON_TABLE too, while SQL Server uses its own OPENJSON.
Some standard features exist in only one or two databases. System-versioned temporal tables (SQL:2011) are built into SQL Server, MariaDB and Db2 (Oracle offers a similar feature called Flashback), but not into PostgreSQL. MATCH_RECOGNIZE (SQL:2016) is in Oracle and a few analytics databases. Property graph queries (SQL:2023) are supported by Oracle Database 23ai, while most other databases don't have them yet. Always check your own database's documentation before relying on a newer feature.
Writing Portable SQL
Most applications run on one database, so total portability is rarely worth chasing. But a few habits make SQL easier to move and easier for others to read:
| Habit | Instead of |
|---|---|
CAST(x AS type) | x::type |
COALESCE(a, b) | IFNULL, ISNULL, NVL |
CASE WHEN ... END | IF(), IIF(), DECODE() |
CURRENT_DATE, CURRENT_TIMESTAMP | now(), GETDATE(), SYSDATE |
JOIN ... ON | Old comma joins with conditions in WHERE |
Identity columns (GENERATED ... AS IDENTITY) | SERIAL, AUTO_INCREMENT (where supported) |
| Unquoted, lowercase names with underscores | Mixed-case names in double quotes |
Keep database-specific code in one place. If the app uses PostgreSQL's ON CONFLICT or SQL Server's MERGE, put it in one data-access module, so a later move changes one file instead of a hundred. The next lesson, Dialect Differences Cheat Sheet, lists the most common differences side by side.
Common Mistakes
Assuming the standard means "works everywhere". Some standard features are missing from popular databases, such as FETCH FIRST in MySQL. Check your target database.
Assuming a dialect feature is standard. LIMIT, ::, ILIKE and SERIAL are PostgreSQL (and some others), not the standard.
Chasing portability for its own sake. If the app will only ever run on PostgreSQL, using a clearly better PostgreSQL feature is fine. Just know you're doing it.
Copying answers from the internet without checking the dialect. A SQL Server answer with TOP and GETDATE() won't run on PostgreSQL as written.
Interview Corner
Is SQL a standard? Who maintains it?
Yes. It is ISO/IEC 9075, maintained by ISO and IEC (with national bodies such as ANSI in the United States). The latest major revision is SQL:2023.
What is a SQL dialect?
A database's version of SQL: the parts of the standard it implements, plus its own extensions and differences, such as LIMIT in PostgreSQL and MySQL or TOP and T-SQL in SQL Server.
Name some differences between PostgreSQL and SQL Server syntax.
Limiting rows (LIMIT vs TOP or OFFSET ... FETCH), joining text (|| vs +), identity columns (GENERATED AS IDENTITY or SERIAL vs IDENTITY), the current time (now() vs GETDATE()), and procedural code (PL/pgSQL vs T-SQL).
Which SQL features are portable across almost all databases?
SELECT, WHERE, joins, GROUP BY, HAVING, ORDER BY, subqueries, INSERT, UPDATE, DELETE, CASE, COALESCE, CAST and basic CREATE TABLE with keys and constraints. Window functions and CTEs are also widely supported in current versions.
Practice
Challenge: Rewrite this PostgreSQL-flavored query using only standard SQL forms, and check that it returns the same rows: SELECT title, fee_usd::int AS fee FROM courses WHERE title ILIKE 'java%' ORDER BY fee DESC LIMIT 2;
Show solution
SELECT title, CAST(fee_usd AS INTEGER) AS fee
FROM courses
WHERE LOWER(title) LIKE 'java%'
ORDER BY fee DESC, title
FETCH FIRST 2 ROWS ONLY; title | fee
------------------+-----
Java Collections | 550
Java OOP | 500
(2 rows)::int becomes CAST(... AS INTEGER), PostgreSQL's case-insensitive ILIKE becomes LOWER(title) LIKE 'java%', and LIMIT 2 becomes FETCH FIRST 2 ROWS ONLY. Adding title to the ORDER BY makes the order certain if two courses ever share a fee. One caution: LOWER follows the database's collation, so for languages other than English, results can differ slightly between databases.
Key Takeaways
| You want to | Standard | Common dialect forms |
|---|---|---|
| Limit rows | FETCH FIRST n ROWS ONLY | LIMIT n, TOP n |
| Convert a type | CAST(x AS type) | x::type, CONVERT() |
Replace NULL | COALESCE(a, b) | IFNULL, ISNULL, NVL |
| Join text | a || b | CONCAT(a, b), a + b |
| Current date | CURRENT_DATE | now()::date, GETDATE(), SYSDATE |
Was this tutorial helpful?