// dialect comparison

Boolean literals: TRUE, 1 and 'Y' in SQL Server, PostgreSQL, MySQL, SQLite and Oracle

TRUE is a keyword in four engines, but only PostgreSQL and Oracle 23ai back it with a real type. SQL Server has no TRUE at all.

Filed under Types & casting

The verdict

PostgreSQL and Oracle 23ai are the only engines where TRUE is a literal of a real boolean type. MySQL and SQLite accept TRUE but store 1, and SQL Server filters BIT columns with = 1. The convention lives in the schema, so check the column type before writing the predicate.

Where they differ

How you write true and false depends entirely on the column type underneath. The rows below filter an active flag in each engine's native convention.

How each engine writes it

SQL Server

SELECT * FROM t WHERE is_active = 1;

The BIT type stores 0 and 1 only; TRUE and FALSE are not keywords, so the literal is the number.

PostgreSQL

SELECT * FROM t WHERE is_active = TRUE;

A real BOOLEAN type accepts TRUE, FALSE, and the literals 't', 'f', 'yes', 'no', '1', '0' when quoted.

MySQL

SELECT * FROM t WHERE is_active = TRUE;

TRUE is just an alias for 1; a BOOLEAN column is really TINYINT(1) and happily stores 7.

SQLite

SELECT * FROM t WHERE is_active = 1;

No boolean type: flags are integers. The TRUE and FALSE keywords are recognized (3.23+) and evaluate to 1 and 0.

Oracle

SELECT * FROM t WHERE is_active = 1;

Before 23ai there is no SQL BOOLEAN, so flags are NUMBER(1) 0/1, as here, or CHAR(1) 'Y'/'N'. On a 23ai BOOLEAN column, WHERE is_active = TRUE and a bare WHERE is_active both work.

Questions that come up

Why did WHERE is_active = TRUE fail on SQL Server?

There is no TRUE keyword there. Use is_active = 1. A bare WHERE is_active fails too (Msg 4145): SQL Server wants a comparison even on BIT columns.

Is MySQL's BOOLEAN a real type?

No. BOOLEAN is an alias for TINYINT(1), and any integer value is accepted. TRUE/FALSE literals simply mean 1/0.

Should I use 'Y'/'N' flags in Oracle?

It is a widespread legacy convention and readable in data dumps, but NUMBER 0/1 or (from 23ai) BOOLEAN compares more naturally and indexes the same. Pick one convention and stick to it.

Keep reading

// write it once, run it anywhere

Switch engines without relearning SQL

SQLly is a native SQL workbench for macOS, Windows and Linux. Its formatter and plan viewer work in all five dialects.