SQL differences

Double Dash Comments Need a Space After Them on MySQL and MariaDB

In a line like SELECT price --discount, left over from debugging, SQLite and PostgreSQL read --discount as a comment. MySQL and MariaDB add the discount to the price instead.

SQLite and PostgreSQL treat every -- as the start of a comment. MySQL and MariaDB need a space, a tab or a line break after the dashes; otherwise they are two minus signs.

SELECT 1 --1, run on four engines: SQLite 3.45.1 1; PostgreSQL 16.15 1; MySQL 8.0.46 2; MariaDB 10.11.14 2.

What Each Engine Answered

The example

SELECT 1 --1;

gave these answers:

Engine Answer
SQLite 3.45.1 1
PostgreSQL 16.15 1
MySQL 8.0.46 2
MariaDB 10.11.14 2

What to Write Instead

This form answers the same on every engine:

SELECT 1 -- 1;
Engine Answer
SQLite 3.45.1 1
PostgreSQL 16.15 1
MySQL 8.0.46 1
MariaDB 10.11.14 1

Put a space after --.

What BareSQL Portable Reports

Saved as example.sql, the example gets this from baresql lint --all:

$ baresql lint --all example.sql
example.sql:1:10: warning: On MySQL and MariaDB, -- starts a comment only when a space follows it, so SELECT 1 --1 is 2 there and 1 elsewhere. [dash-comment]
    --1;
    Put a space after --.

1 problem: 1 warning.

baresql rules dash-comment prints the same answers in the terminal, and the BareSQL Portable page lists every difference BareSQL knows.