SQL differences

A Backslash Is an Escape Character in MySQL Strings and a Plain Character in PostgreSQL

A Windows path written as 'C:\temp\new' reads back on MySQL and MariaDB with a tab and a line break in it. PostgreSQL and SQLite keep the backslashes as typed.

'C:\\temp' is C:\\temp, two backslashes, on SQLite and PostgreSQL and C:\temp on MySQL and MariaDB. '\t' is a tab and '\'' a quote there, while PostgreSQL needs its E'...' strings for escapes, which no other engine reads. MySQL’s NO_BACKSLASH_ESCAPES mode makes it read backslashes like the others.

SELECT 'C:\\temp', run on four engines: SQLite 3.45.1 'C:\\temp'; PostgreSQL 16.15 'C:\\temp'; MySQL 8.0.46 'C:\temp'; MariaDB 10.11.14 'C:\temp'.

What Each Engine Answered

The example

SELECT 'C:\\temp';

gave these answers:

Engine Answer
SQLite 3.45.1 'C:\\temp'
PostgreSQL 16.15 'C:\\temp'
MySQL 8.0.46 'C:\temp'
MariaDB 10.11.14 'C:\temp'

Every Form BareSQL Checks

BareSQL Portable checks 3 forms of this, and each was run on all four engines. yes means the engine ran it and the engines that ran it agreed, no means the engine refused it, and a value is what the engine answered where they disagreed.

Form SQLite PostgreSQL MySQL MariaDB What to write instead
backslash 'C:\\temp' 'C:\\temp' 'C:\temp' 'C:\temp'
E'...' no yes no no
\' no no yes yes Write a quote inside a string as two quotes: 'it''s'.

What to Write Instead

Keep backslashes out of SQL string literals: pass such values as query parameters, which every driver sends without escaping.

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: MySQL and MariaDB read a backslash in a string as an escape character; SQLite and PostgreSQL keep it as a backslash. [backslash-escapes]
    'C:\\temp'
    Keep backslashes out of SQL string literals: pass such values as query parameters, which every driver sends without escaping.

1 problem: 1 warning.

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