Skip to main content

Posts

Showing posts with the label SQLite

When simple SQL can be complex

I think SQL is a very simple language, but ofcourse I'm biased. But even a simple statement might have more complexity to it than you might think. Do you know what the result is of this statement? SELECT FALSE = FALSE = TRUE; scroll down for the answer. The answer is: it depends. You might expect it to return false because the 3 items in the comparison are not equal. But that's not the case. In PostgreSQL this is the result: postgres=# SELECT FALSE = FALSE = TRUE; ?column? ---------- t (1 row) So it compares FALSE against FALSE, which results in TRUE and then That is compared against TRUE, which results in TRUE. PostgreSQL has proper boolean literals . Next up is MySQL: mysql> SELECT FALSE = FALSE = TRUE; +----------------------+ | FALSE = FALSE = TRUE | +----------------------+ | 1 | +----------------------+ 1 row in set (0.00 sec) This is similar but it's slightly different. The result is 1 because in My...

Same query, 3 databases, 3 different results

The SQL standard leaves a lot of room for different implementations. This is a little demonstration of one of such differences. SQLite  3.7.4 sqlite> create table t1 (id serial, t time); sqlite> insert into t1(t) values ('00:05:10'); sqlite> select t,t*1.5 from t1; 00:05:10|0.0 MySQL 5.6.4-m5 mysql> create table t1 (id serial, t time); Query OK, 0 rows affected (0.01 sec) mysql> insert into t1(t) values ('00:05:10'); Query OK, 1 row affected (0.00 sec) mysql> select t,t*1.5 from t1; +----------+-------+ | t        | t*1.5 | +----------+-------+ | 00:05:10 |   765 | +----------+-------+ 1 row in set (0.00 sec) PostgreSQL 9.0.3 test=# create table t1 (id serial, t time); NOTICE:  CREATE TABLE will create implicit sequence "t1_id_seq" for serial column "t1.id" CREATE TABLE test=# insert into t1(t) values ('00:05:10'); INSERT 0 1 test=# select t,t*1.5 from t1;     t ...