Archive for January, 2010

Experience Liberia – All The Episodes of The Vice Guide to Liberia

Monday, January 25th, 2010

While browsing around the Internet, I came upon a rather startling series of videos. These videos were the first, in quite a long time, where I had to stop part way through and take a break. They show the absolutely staggering poverty and conditions that exist within the country of Liberia.

BE WARNED that these videos are not for the faint of heart in any stretch of the imagination. However, if you are willing to experience what exists in our world, then these videos will challenge you. I bring you, The Vice Guide to Liberia.

Part I:

Part II:

Part III:

Part IV:

Part V:

Part VI:

Part VII:

Part VIII:

I don’t know if the other parts haven’t been published, or what, but right now, I could not find the links to part 7 and 8… but damn, this is some captivating reporting. The remaining episodes have been posted as they have been released.

If you liked this post, then please, consider subscribing to my feed.

Random Dates and Numbers in PostgreSQL with the RANDOM() Function

Wednesday, January 20th, 2010

Working with the random() function in PostgreSQL can be a bit tricky if you’re trying to populate a table.

The random() function in PostgreSQL will return a number between 0 and 1 like so:

SELECT RANDOM();
      random       
-------------------
 0.115072432027698
(1 row)

If you’re trying to get a whole number from random(), you can use some multiplication and the round() function to let random() work for you. Say you wanted to get a random number from 0-100:

SELECT ROUND(RANDOM() * 100);
 round 
-------
    22
(1 row)

For the project I’m working on, we wanted to pre-populate some birthdays with random dates. I tried using a combination of the datetime functions with an interval and random() and couldn’t quite get there. Searching around on Google didn’t provide too many useful results so I turned to the wonderful folks in the #postgresql chat at irc.freednode.net. Using a combination of the above and the suggestions from the chat room, I was able to come up with a query that did what I wanted:

SELECT NOW() - '1 year'::INTERVAL * ROUND(RANDOM() * 100);
           ?COLUMN?           
------------------------------
 1987-01-20 11:10:34.26494-07
(1 row)

That means we could easily update our tables for people with random birthdays with a single update query:

UPDATE table_name SET birthday = NOW() - '1 year'::INTERVAL * ROUND(RANDOM() * 100);

Hopefully you found this post useful. If you did, please consider subscribing to my feed.