[Haskell-cafe] Handling Postgresql array types

Amit Aryeh Levy amit at amitlevy.com
Fri Dec 26 06:22:50 UTC 2014


I doubt you'd need to extend the built-in conversion functions for
postgresql-simple. In particular there is already an instance fo
`ToField` for:

`ToField a => ToField (Vector a)`

meaning there is an instance for the type `Vector (Vector Float)`
(because `Float` is also an instance of `ToField`). I believe that
should work out of the box for you. I've never tried using two
dimensional arrays, but I've used postgresql arrays as Vectors using
postgresql-simple a lot, and it works great out of the box.

If you're interested in going just a little bit higher level without
abandoning postgresql-simple, I'd suggest postgresql-orm (shameless
plug), which gives you an very lightweight ORM layer on top of
postgresql-simple -- specifically a safe query DSL.

-Amit

On 12/25/2014 07:36 PM, Riaan wrote:
> This is a question about database query libraries.  I am trying to do
> some analytics on a Postgresql database and up to now have been using
> Database.HDBC for most of my querying.
>
> One of the columns on the database is a two dimensional float8 array. 
> I tried using Database.PostgreSQL.Simple but got stuck on this array
> as I could not figure out how to extend the built in conversion
> functions to cater for something like this.  So went back to HDBC. 
> But now my queries are starting to get fairly long and I have been
> looking at libraries like Persistent with Esqualeto, HaskellDB and
> Groundhog to make my queries a little more composable and type safe.  
>
> However I have not been able to find any examples of any of these
> libraries using postgres arrays and given my postgresql-simple
> experience I worried that I might similarly be unable, because of my
> low level of haskell ability, to extend the conversion functions.
>
> So to my question.  Does anyone have experience with one of these
> libraries in dealing with postgresql arrays and could someone perhaps
> send me a simple example that I could use as a basis.  Failing that,
> can anyone advise me on which of these libraries have the most haskell
> newbie (LYAH trained, but still struggling with RWH) friendly approach
> to writing new conversion functions?
>
> Thanks
> Riaan
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20141225/3426d24f/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: OpenPGP digital signature
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20141225/3426d24f/attachment.sig>


More information about the Haskell-Cafe mailing list