http://archives.postgresql.org/pgsql-general/2003-07/msg01507.php

how to convert hex to decimal in Postgres