<div dir="ltr">Thank you for pointing me in the right way.  This does almost what I want.  However I want to end up with a [[Double]] rather than (PGArray (PGArray Double)). <div><br></div><div>I know I can do the conversion using fromPGArray but I was hoping to use the fromRow instances to remove some of the boilerplate.</div><div><br></div><div>So I have:</div><div><div>data IIM = IIM {key :: String</div><div>               ,itype :: String</div><div>               ,idet :: Maybe String</div><div>               ,imat :: (PGArray (PGArray Double))} deriving (Read, Show, Eq)</div><div><br></div><div>instance FromRow IIM where </div><div>  fromRow = IIM <$> field <*> field <*> field <*> field</div><div><br></div><div>Which works fine, but I would actually like my data IIM to be:</div><div><div><br></div><div>data IIM = IIM {key :: String</div><div>               ,itype :: String</div><div>               ,idet :: Maybe String</div><div>               ,imat :: [[Double]]} deriving (Read, Show, Eq)</div><div><br></div></div><div>But I can't figure out how to get a fromRow instance for that, otherwise I need to return SQL results in a (,,,,) and then create the IIM from that which seems a lot of extra typing.</div><div><br></div><div>PS. I started looking into Opaleye as a possible DSL and would appreciate any help you can give me in figuring out how to represent arrays in that.  I am assuming I need to do something with queryRunnerColumn but I was not able to understand the example.</div><div><br></div>On Friday, December 26, 2014 10:02:21 PM UTC+11, Tom Ellis wrote:<blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On Fri, Dec 26, 2014 at 10:52:46AM +0000, Tom Ellis wrote:
<br>> On Fri, Dec 26, 2014 at 02:36:07PM +1100, Riaan wrote:
<br>> > So went back to HDBC.  But now my queries are starting to get fairly long
<br>> > and I have been looking at libraries like Persistent with Esqualeto,
<br>> > HaskellDB and Groundhog to make my queries a little more composable and
<br>> > type safe.
<br>> 
<br>> Don't forget to look at Opaleye too :)  It doesn't really have much support
<br>> for arrays at the moment, but if you let me know what you want to do I'm
<br>> happy to help you.
<br>> 
<br>> > So to my question.  Does anyone have experience with one of these libraries
<br>> > in dealing with postgresql arrays
<br>> 
<br>> postgresql-simple has
<br>> 
<br>>     instance (FromField a, Typeable a) => FromField (PGArray a)
<br>> 
<br>> Does that not do exactly what you want?
<br>
<br>import Database.PostgreSQL.Simple (query_, ConnectInfo(..), connect, Only)
<br>import Database.PostgreSQL.Simple.<wbr>Types (PGArray)
<br>
<br>import Data.String (fromString)
<br>
<br>connectInfo :: ConnectInfo
<br>connectInfo =  ConnectInfo { connectHost = "localhost"
<br>                           , connectPort = 25433
<br>                           , connectUser = "tom"
<br>                           , connectPassword = "tom"
<br>                           , connectDatabase = "opaleye_test" }
<br>
<br>arrayQuery :: String
<br>arrayQuery = "select '{{1,2}, {3,4}}' :: integer[][]"
<br>
<br>main :: IO ()
<br>main = do
<br>  conn <- connect connectInfo
<br>  results <- query_ conn (fromString arrayQuery) :: IO [Only (PGArray (PGArray Int))]
<br>  print results
<br>              
<br>-- Output
<br>--
<br>-- ghci> main
<br>-- [Only {fromOnly = PGArray {fromPGArray = [PGArray {fromPGArray = [1,2]},PGArray {fromPGArray = [3,4]}]}}]
<br>______________________________<wbr>_________________
<br>Haskell-Cafe mailing list
<br><a href="javascript:" target="_blank" gdf-obfuscated-mailto="4847yho1PCQJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">Haskel...@haskell.org</a>
<br><a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fwww.haskell.org%2Fmailman%2Flistinfo%2Fhaskell-cafe\46sa\75D\46sntz\0751\46usg\75AFQjCNHiVycCM53czUVzPma4Fkb_wPqP2A';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fwww.haskell.org%2Fmailman%2Flistinfo%2Fhaskell-cafe\46sa\75D\46sntz\0751\46usg\75AFQjCNHiVycCM53czUVzPma4Fkb_wPqP2A';return true;">http://www.haskell.org/<wbr>mailman/listinfo/haskell-cafe</a>
<br></blockquote></div></div>