updated for supporting postgres versions above 9.2