SQL differences

LOG With One Argument Is Base 10 on PostgreSQL and the Natural Logarithm on MySQL

A score or a scale built on LOG() shifts when the code moves to another engine, because LOG(100) doesn’t mean the same logarithm everywhere.

LOG(100) is 2 on SQLite and PostgreSQL and 4.605 on MySQL and MariaDB. With two arguments, LOG(b, x) is the logarithm of x to base b on all four. SQLite has LOG, LN, LOG10 and POWER only when it is built with its math functions: the sqlite3 program is by default since version 3.35, and some systems ship it without them.

SELECT LOG(100), run on four engines: SQLite 3.45.1 2.0; PostgreSQL 16.15 2; MySQL 8.0.46 4.605170185988092; MariaDB 10.11.14 4.605170185988092.

What Each Engine Answered

The example

SELECT LOG(100);

gave these answers:

Engine Answer
SQLite 3.45.1 2.0
PostgreSQL 16.15 2
MySQL 8.0.46 4.605170185988092
MariaDB 10.11.14 4.605170185988092

The SQLite answers assume a build with math functions.

What to Write Instead

This form answers the same on every engine:

SELECT LOG10(100);
Engine Answer
SQLite 3.45.1 2.0
PostgreSQL 16.15 2
MySQL 8.0.46 2
MariaDB 10.11.14 2

Say which one you mean: LN(x) for the natural logarithm, LOG10(x) for base 10.

What BareSQL Portable Reports

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

$ baresql lint --all example.sql
example.sql:1:8: warning: LOG(x) is the base-10 logarithm on SQLite and PostgreSQL and the natural logarithm on MySQL and MariaDB. [log-base]
    LOG(100)
    Say which one you mean: LN(x) for the natural logarithm, LOG10(x) for base 10.

1 problem: 1 warning.

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