
John Goerzen wrote:
Tim Docker wrote:
Yes. I can use fromSql to convert the result back to an appropriate numerical type. But internally the numeric data has still been converted to an intermediate string representation. I'm wondering if this is intentional, and whether it matters.
Yes and no, in that order.
A ByteString is a pretty universal holder for various types of data. As someone else pointed out, at query time, we don't really have access to what type you will eventually want to use it as, and supporting the vast number of different ways to get things out of databases -- with the corresponding complexities of how a database driver can convert between them -- was just not worth it.
It is generally assumed that the end user will be using fromSql anyhow, so it is not particularly relevant if it's a SqlByteString or a SqlInteger internally.
I was wondering whether going via an intermediate string might cause issues relating to loss of precision in floating point values, or possible date conversion problems if locales were not set correctly. I'm seeing problems with date conversion, and wonder if this is related. Depending on my intended result type, I see conversion errors, in particular the 3rd example below seem to be related to formatting of the intermediate string: *Main> fmap (fromSql.head.head) $ quickQuery c "select getdate()" [] :: IO Data.Time.Clock.UTCTime 2010-04-09 09:59:20.67 UTC *Main> fmap (fromSql.head.head) $ quickQuery c "select getdate()" [] :: IO Data.Time.LocalTime 2010-04-09 09:59:26.313 *Main> fmap (fromSql.head.head) $ quickQuery c "select getdate()" [] :: IO System.Time.CalendarTime *** Exception: Convertible: error converting source data SqlString "2010-04-09 09:59:37.460" of type SqlValue to type Data.Time.LocalTime.LocalTime.ZonedTime: Cannot parse using default format string "%Y-%m-%d %T%Q %z" *Main> fmap (fromSql.head.head) $ quickQuery c "select getdate()" [] :: IO System.Time.ClockTime *** Exception: Convertible: error converting source data SqlString "2010-04-09 09:59:49.940" of type SqlValue to type Integer: Cannot read source value as dest type Thanks, Tim