Content here is by:
Michael Still
mikal@stillhq.com

All my Open Source projects
Online CVS server
Extracted view of CVS
Home
Site map
July 2008
Sun Mon Tue Wed Thu Fri Sat
   
   

ImageMagick book
MythTV book





Mon, 12 May 2008



Discovering the CASE statement

    In an effort to speed up my database updates, I've been looking for ways to batch some of my updates. CASE seems like the way to go:

    mysql> create table bar(a tinyint, b tinyint);
    Query OK, 0 rows affected (0.02 sec)
    
    mysql> insert into bar(a) values(1), (2), (3), (4), (5);
    Query OK, 5 rows affected (0.00 sec)
    Records: 5  Duplicates: 0  Warnings: 0
    
    mysql> select * from bar;
    +------+------+
    | a    | b    |
    +------+------+
    |    1 | NULL | 
    |    2 | NULL | 
    |    3 | NULL | 
    |    4 | NULL | 
    |    5 | NULL | 
    +------+------+
    5 rows in set (0.00 sec)
    
    mysql> update bar set b = case a
        ->   when 1 then 42
        ->   when 2 then 43
        ->   when 3 then 44
        ->   else 45
        ->   end;
    Query OK, 5 rows affected (0.00 sec)
    Rows matched: 5  Changed: 5  Warnings: 0
    
    mysql> select * from bar;
    +------+------+
    | a    | b    |
    +------+------+
    |    1 |   42 | 
    |    2 |   43 | 
    |    3 |   44 | 
    |    4 |   45 | 
    |    5 |   45 | 
    +------+------+
    5 rows in set (0.00 sec)
    


    I see stuff online which warns not to forget the else, otherwise you get a default of null, so I guess I should bear that caveat in mind...

    Tags for this post: mysql(S)

posted at: 14:11 | path: /mysql | permanent link to this entry
There are 4 comments on this post, and 2 comments which didn't survive moderation. 0 were blocked by trained gerbils. Click here to see them.


I, Robot

    The 1950s must have been a great time to be a science fiction author. WW2 was finally over, and seemingly massively stupid ideas like mutually assured destruction, nuclear rifles so powerful that they were as much a danger to those firing them as those who were on the receiving end, and Brylcreem were all the rage. Into this atmosphere of run away idiocy comes Asimov's I, Robot, the book which defined the three laws of robotics, and some how managed to not suggest that humanity should nuke each other all into submission. This book is still an excellent read almost 60 years later, and I think still shows us some of the future. Its a little depressing to think how little we've achieved towards Asimov's proposed future world, given the time line laid out in this book.

    One of the interesting aspects of this book is Asimov's failure to predict things which seem so mundane now, but must have not been obvious to an observer in 1950. For example:

    • The commonness of computers now. One of the short stories revolves around a secret batch of robots, and the need to debug them. The protagonists can't use a computer though, because that would draw too much attention. Why not use a laptop? Because Asimov failed to predict them.
    • The use of wire recorders to record sound. No optical media (or whatever we'll have in the future) here.
    • The assumption that robots contain vacuum tubes.
    • The failure to account for inflation. This one should have been obvious! A batch of 63 robots for instance is valued at $2 million dollars in one of the stories, a sum so great that no one can conceive of deliberately destroying the batch.


    A good book.

    Tags for this post: book(S) Isaac_Asimov(S)

posted at: 05:32 | path: /book/Isaac_Asimov | permanent link to this entry
There are no comments on this post yet. Be the first to make one.