SQL comparison between boolean values can lead to unexpected results
<p>Why do most (all?) SQL databases give the following results: </p>
<pre class="brush:php;toolbar:false;">SELECT FALSE < FALSE; -- FALSE / 0 Ok
SELECT TRUE < FALSE; -- FALSE / 0 Ok
SELECT NOT(FALSE) < FALSE; -- TRUE / 1 What?
SELECT NOT(TRUE) < FALSE; -- TRUE / 1 What? ? </pre>
<p>Just to double-check: </p>
<pre class="brush:php;toolbar:false;">SELECT NOT(TRUE) = FALSE; -- TRUE / 1 Ok
SELECT NOT(FALSE) = TRUE; -- TRUE / 1 Ok</pre>
<p>In Postgres I can also check: </p>
<pre class="brush:php;toolbar:false;">SELECT pg_typeof(TRUE), pg_typeof(NOT(FALSE));
-- boolean | boolean</pre>
<p>I've tried PostgreSQL, SQLite3 and MariaDB and they all gave the same unexpected results. </p><p>
<strong>What am I missing? </strong></p>