You can use the hg-git extension for that:
5 karma · joined March 10, 2013
https://redmonk.com/dberkholz/2012/09/07/opening-the-infrast...
https://softwareengineering.stackexchange.com/questions/5803...
I wish there was an equivalent function in PostgreSQL. I've even asked a question about that on stackoverflow:
https://stackoverflow.com/questions/8637050/cursor-inside-sq...