Skip to main content

Posts

Showing posts with the label standards

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...

time for standards

MySQL 5.6 includes support for microsecode timestamp resolution , which is a great new feature. To get the current timestamp in MySQL 5.5 you could use NOW(), SYSDATE() or CURRENT_TIMESTAMP. mysql_5.5> SELECT NOW(),SYSDATE(),CURRENT_TIMESTAMP; +---------------------+---------------------+---------------------+ | NOW() | SYSDATE() | CURRENT_TIMESTAMP | +---------------------+---------------------+---------------------+ | 2013-10-26 15:46:24 | 2013-10-26 15:46:24 | 2013-10-26 15:46:24 | +---------------------+---------------------+---------------------+ 1 row in set (0.01 sec) If we run the same statement in MySQL 5.6 the output is the same. This is great for compatibility, but what if we want those microsecond timestamps? mysql_5.6> SELECT NOW(),SYSDATE(),CURRENT_TIMESTAMP; +---------------------+---------------------+---------------------+ | NOW() | SYSDATE() | CURRENT_TIMESTAMP | +---------------------+----------------...