SQL differences

MySQL Refuses a Plain DEFAULT Value on TEXT Columns

A notes column declared as TEXT DEFAULT '' works on SQLite, PostgreSQL and MariaDB. MySQL refuses the CREATE TABLE.

MySQL 8.0.13 and later accept a default written as an expression in parentheses, DEFAULT ('a'), which the other three engines accept as well.

CREATE TABLE t (id INTEGER, x TEXT DEFAULT 'a'); INSERT INTO t (id) VALUES (1); SELECT x FROM t, run on four engines: SQLite 3.45.1 'a'; PostgreSQL 16.15 'a'; MySQL 8.0.46 error: BLOB, TEXT, GEOMETRY or JSON column 'x' can't have a default value; MariaDB 10.11.14 'a'.

What Each Engine Answered

The example

CREATE TABLE t (id INTEGER, x TEXT DEFAULT 'a');
INSERT INTO t (id) VALUES (1);
SELECT x FROM t;

gave these answers:

Engine Answer
SQLite 3.45.1 'a'
PostgreSQL 16.15 'a'
MySQL 8.0.46 error: BLOB, TEXT, GEOMETRY or JSON column 'x' can't have a default value
MariaDB 10.11.14 'a'

What to Write Instead

This form answers the same on every engine:

CREATE TABLE t (id INTEGER, x TEXT DEFAULT ('a'));
INSERT INTO t (id) VALUES (1);
SELECT x FROM t;
Engine Answer
SQLite 3.45.1 'a'
PostgreSQL 16.15 'a'
MySQL 8.0.46 'a'
MariaDB 10.11.14 'a'

Put the default in parentheses, DEFAULT ('a'), or use VARCHAR(n).

What BareSQL Portable Reports

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

$ baresql lint --all example.sql
example.sql:1:36: error: MySQL refuses a plain DEFAULT value on TEXT, BLOB and JSON columns; SQLite, PostgreSQL and MariaDB accept it. [text-default]
    DEFAULT 'a'
    Put the default in parentheses, DEFAULT ('a'), or use VARCHAR(n).

1 problem: 1 error.

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