Thursday, April 7, 2011

(From MySQL to postgresql / sql in action) -> sed utility/regExp

  • You know I always speak my mind, so I asked professor Andrade today: who uses postgresql anyway? He named several public organizations and a couple of businesses here in México, so I was like: mmm, ok then, that sounds good to me . Here's the official list, containing the best known organizations using postgresql:, so postgresql is quite something for that matter. This link is  mind blowing:

  • It's quite a coincidence but I happened to find the infamous iraq war logs in my disk drive (a mysql sqldump weighing about 360 MB), I have no idea of how did they get there (really!), but let's use it for didactical  purposes.

  • The first thing I wan't to do is to transform this mysql dump file  into a working postgresql database. So I'm using this guide: <-didn't work too many errors

  • Ok let's give this perl script a try:, by postgres.  <- didn't work either

I'm learning to use the sed utility (to fix those idiomatic errors) , found a marvelous tutorial here:

and on regular expressions:

I just love wonderful people making wonderful tutorials!

  • To finish this post, I'll say that from all the things we learned today the most important were:

  1. The case clause. We used it to say: if this guy is over 21 years, give me the word : "adult", else give me the word "minor". i.e: SELECT * , CASE when age>21 then 'adult' else 'minor' end FROM friends;

  2. 1::integer -> sort of a cast

  3. ILIKE. for case insensitive regular expressions

  4. Coalesce. Returns the first not null field. <- need to review it, I didn't quite get it =-D.

No comments:

Post a Comment