SQL differences

PostgreSQL Returns Column Names in Lower Case Unless You Quote Them

SELECT SUM(amount) AS Total gives a column named Total on SQLite, MySQL and MariaDB. PostgreSQL calls it total.

SQLite, MySQL and MariaDB return names as written. PostgreSQL folds unquoted names to lower case, in aliases and in CREATE TABLE alike, so code that reads columns by name (row["Total"]) finds nothing on PostgreSQL.

SELECT 1 AS Total, run on four engines: SQLite 3.45.1 columns Total: 1; PostgreSQL 16.15 columns total: 1; MySQL 8.0.46 columns Total: 1; MariaDB 10.11.14 columns Total: 1.

What Each Engine Answered

The example

SELECT 1 AS Total;

gave these answers:

Engine Answer
SQLite 3.45.1 columns Total: 1
PostgreSQL 16.15 columns total: 1
MySQL 8.0.46 columns Total: 1
MariaDB 10.11.14 columns Total: 1

What to Write Instead

This form answers the same on every engine:

SELECT 1 AS total;
Engine Answer
SQLite 3.45.1 columns total: 1
PostgreSQL 16.15 columns total: 1
MySQL 8.0.46 columns total: 1
MariaDB 10.11.14 columns total: 1

Use lower-case names for columns and aliases.

What BareSQL Portable Reports

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

$ baresql lint --all example.sql
example.sql:1:13: warning: PostgreSQL returns the column Total as total; SQLite, MySQL and MariaDB return Total. [column-name-case]
    Total
    Use lower-case names for columns and aliases.

1 problem: 1 warning.

baresql rules column-name-case prints the same answers in the terminal, and the BareSQL Portable page lists every difference BareSQL knows.