nikita-volkov / postgresql-binary

Encoders and decoders for the PostgreSQL's binary format
http://hackage.haskell.org/package/postgresql-binary
MIT License
21 stars 13 forks source link

Not sure how to use correctly #10

Closed echatav closed 7 years ago

echatav commented 7 years ago

Hello, I'm trying to use postgresql-binary to decode values retrieved using postgresql-libpq. I'm sure I'm doing something wrong but figured I'd ask for help. Here's a minimal example.

> connection <- connectdb "host=localhost port=5432 dbname=exampledb"
> Just result <- exec connection "SELECT 5::int4;"
> Just bytes <- getvalue result 0 0
> let Right (value :: Int32) = valueParser int bytes
> finish connection
> value
53
> bytes
"5"

So, it's clear that the decoder is treating "5" as its ASCII code. Maybe I need to change some setting in postgres?

echatav commented 7 years ago

I got it. exec gives back a Text formatted result. It works with execParams requesting a Binary formatted result. That's annoying that exec doesn't allow requesting a Binary formatted result.