If anyone cares I have figured out how to do this. I use SPI_getbinval and it works perfectly
pgsql-general by date:
Соглашаюсь с условиями обработки персональных данных