opyeb sqllint

sqllint · Dialects

PostgreSQL, MySQL and SQLite differences

Identifier quoting, auto-increment, casts, LIMIT and OFFSET, case sensitivity

Even for standard SQL, the number of statements all three databases accept unchanged is smaller than it looks. When an application moves to another engine, or when tests run on SQLite while production runs on PostgreSQL, these five differences are what break first.

Quoting identifiers

DatabaseQuoteNote
PostgreSQL"col"Double quotes mark an identifier; single quotes mark a string.
MySQL`col`By default double quotes read as a string.
SQLite"col", `col`, [col]Several forms are accepted, but double quotes are standard.

A quoted identifier is case sensitive. "User" and user are two different names in PostgreSQL. Unquoted names fold to lower case, so a mixed-case name must always be quoted.

Auto-increment columns

In SQLite, AUTOINCREMENT may follow INTEGER PRIMARY KEY and nothing else. Moving a MySQL AUTO_INCREMENT across unchanged is a syntax error. This tool warns when the auto-increment spelling does not belong to the chosen dialect.

Casts and string concatenation

PostgreSQL accepts both value::type and CAST(value AS type), while MySQL and SQLite have no ::. Concatenation differs too: the standard || works in PostgreSQL and SQLite, and MySQL needs CONCAT() or the PIPES_AS_CONCAT mode.

LIMIT and OFFSET

All three accept LIMIT n OFFSET m. MySQL also allows LIMIT m, n, where the first number is how many rows to skip and the second how many to take. Move that statement elsewhere and LIMIT 10, 20 is a syntax error. Page arithmetic is where the reversed numbers cause bugs.

Case-insensitive comparison

MySQL's default collation is case insensitive, so 'Kim' = 'kim' is true. PostgreSQL and SQLite are case sensitive. If a port changes the number of rows returned, suspect this first. In the other direction, ILIKE gives PostgreSQL a case-insensitive comparison, while MySQL and SQLite need LOWER().

Check the same statement under each dialect. This tool reports the spellings that are likely to fail for the chosen dialect and names the replacement.

Questions

Does SQLite enforce declared types?

No. It uses type affinity, so a value of another type can be stored. Keeping types consistent in the application is safer.

What happens to MySQL backticks in PostgreSQL?

They must become double quotes; a backtick is a syntax error in PostgreSQL.

Is there a date function all three accept?

Almost none. PostgreSQL has <code>now()</code>, MySQL has <code>NOW()</code> and <code>CURRENT_TIMESTAMP</code>, SQLite has <code>CURRENT_TIMESTAMP</code> and <code>datetime('now')</code>. Standard <code>CURRENT_TIMESTAMP</code> is the safest.

Switch the dialect on the SQL you are porting and the trouble spots appear at once.

Open the tool

This article follows the published documentation of PostgreSQL 17, MySQL 8.4 and SQLite 3.46. Every table, column and value shown is synthetic.