FireStats error : Database error: Unknown column 'type' in 'field list'

MySQL Version: 5.0.88-userstats-log
SQL Query:
INSERT DELAYED INTO `wp_firestats_pending_data` ( `timestamp`, `site_id` , `url` , `referrer` , `useragent` , `ip`, `type` ) VALUES ( NOW(), '1', 'http://journal.naveeng.com/2007/10/17/perl-one-liner-to-sort-and-hash-and-return-the-top-most-keyvalue/', '', 'CCBot/1.0 (+http://www.commoncrawl.org/bot.html)', '38.107.191.90', NULL )

Perl one-liner to sort a hash and return the top most key/value

A while ago Deepz asked me whether we can sort a hash and print the top most key or value or both in a single line, in PERL. After a little permutation & combination, I wrote the following piece. I’m sure there must be a more elegant and efficient way of doing it, but this will also serve the purpose on most occasions and with a little tweaking can be applied to almost all hashes.

  • The code needs to be modified if the hash keys contain any digits
  • The sort algorithm can be changed as per the requirement, by default I’m sorting by hash values which are digits

print grep {s/\d//g} grep {/1/} map { $i+=1 , $_.=$i , “\n”} sort {$hash{$a} <=> $hash{$b}} keys %hash;

Spread the Word:
  • Digg
  • del.icio.us
  • StumbleUpon
  • Slashdot
  • Netvouz
  • DZone
  • blogmarks
  • Furl
  • IndiaGram
  • IndianPad
  • Reddit
  • Simpy
  • e-mail
  • Facebook
  • Google Bookmarks
  • Live
  • Technorati
  • YahooMyWeb
  • TwitThis

RSS feed | Trackback URI

Comments »

No comments yet.

Name (required)
E-mail (required - never shown publicly)
URI
Subscribe to comments via email
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.

Trackback responses to this post

Database error: Unknown column 'url_site_id' in 'where clause'

MySQL Version: 5.0.88-userstats-log
SQL Query:
SELECT COUNT(*) FROM `wp_firestats_hits` h WHERE `url_site_id` = 1 AND 1 pages viewed, Database error: Unknown column 'url_site_id' in 'where clause'

MySQL Version: 5.0.88-userstats-log
SQL Query:
SELECT COUNT(*) FROM `wp_firestats_hits` h WHERE `url_site_id` = 1 AND `timestamp` >= FROM_UNIXTIME(1268225019) today
Database error: Unknown column 'url_site_id' in 'where clause'

MySQL Version: 5.0.88-userstats-log
SQL Query:
SELECT SUM(u.c) c FROM (SELECT COUNT(DISTINCT ip_int1, ip_int2) c FROM `wp_firestats_hits` h WHERE `url_site_id` = 1 AND 1 GROUP BY SUBSTRING(`timestamp`,1,10),url_site_id) u visits, Database error: Unknown column 'url_site_id' in 'where clause'

MySQL Version: 5.0.88-userstats-log
SQL Query:
SELECT SUM(u.c) c FROM (SELECT COUNT(DISTINCT ip_int1, ip_int2) c FROM `wp_firestats_hits` h WHERE `url_site_id` = 1 AND `timestamp` >= FROM_UNIXTIME(1268225019) GROUP BY SUBSTRING(`timestamp`,1,10),url_site_id) u today
FireStats icon Powered by FireStats