SQL differences

SQLite Has No CREATE OR REPLACE VIEW

CREATE OR REPLACE VIEW lets a migration change a view in one step on PostgreSQL, MySQL and MariaDB. On SQLite the statement is a syntax error.

SQLite can only drop a view and create it again.

CREATE OR REPLACE VIEW v AS SELECT x FROM t; SELECT COUNT(*) FROM v, run on four engines: SQLite 3.45.1 error: near "OR": syntax error; PostgreSQL 16.15 0; MySQL 8.0.46 0; MariaDB 10.11.14 0.

What Each Engine Answered

On a table made with

CREATE TABLE t (x INTEGER);

the example

CREATE OR REPLACE VIEW v AS SELECT x FROM t;
SELECT COUNT(*) FROM v;

gave these answers:

Engine Answer
SQLite 3.45.1 error: near "OR": syntax error
PostgreSQL 16.15 0
MySQL 8.0.46 0
MariaDB 10.11.14 0

Every Form BareSQL Checks

BareSQL Portable checks 2 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
VIEW no yes yes yes
TABLE no no no yes

What to Write Instead

This form answers the same on every engine:

DROP VIEW IF EXISTS v;
CREATE VIEW v AS SELECT x FROM t;
SELECT COUNT(*) FROM v;
Engine Answer
SQLite 3.45.1 0
PostgreSQL 16.15 0
MySQL 8.0.46 0
MariaDB 10.11.14 0

Drop and create: DROP VIEW IF EXISTS v, then CREATE VIEW v AS ...

What BareSQL Portable Reports

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

$ baresql lint --all example.sql
example.sql:2:1: error: CREATE OR REPLACE VIEW works on PostgreSQL, MySQL and MariaDB; SQLite refuses it. [create-or-replace]
    CREATE OR REPLACE VIEW
    Drop and create: DROP VIEW IF EXISTS v, then CREATE VIEW v AS ...

1 problem: 1 error.

baresql rules create-or-replace prints the same answers in the terminal, and the BareSQL Portable page lists every difference BareSQL knows.