1
我知道此問題已在past before中提出,現在標記爲已解決。在Postgresql中檢索帶時區的時間戳 - 簡單
我正在使用postgresql-simple
包和Data.Time
。如果我進行查詢以檢索timestamptz
類型的單個列,則會發生模式匹配錯誤。下面的僞代碼:
import Data.Text as T
import Data.Time (UTCTime,LocalTime,ZonedTime)
import Database.PostgreSQL.Simple as Pg
import Database.PostgreSQL.Simple.FromRow
import Database.PostgreSQL.Simple.ToRow
import Database.PostgreSQL.Simple.ToField
import Database.PostgreSQL.Simple.Time
import qualified Data.Vector as V
...
--- in main this is the code
[Pg.Only (i::UTCTime)] <- Pg.query conn "select lastupdated from constraints where name=?" (Only ("carrier"::T.Text))
...
執行查詢時,我在運行時出現此錯誤(請注意上面:
*** Exception: user error (Pattern match failure in do expression at ...)
如果我上面更改爲無效類型象下面這樣:
[Pg.Only (i::T.Text)] <- Pg.query conn "select lastupdated from constraints where name=?" (Only ("carrier"::T.Text))
我收到的例外情況顯示預期類型的確是timestamptz
:
*** Exception: Incompatible {errSQLType = "timestamptz",...,
errSQLField = "lastupdated", errHaskellType = "Text", errMessage = "types incompatible"}
此外,這是上面的查詢結果如何看起來psql
控制檯:
lastupdated
-------------------------------
2016-04-13 00:08:33.789761+00
2016-04-13 14:33:38.27739+00
(2 rows)
我的理解是,Data.Time.UTCTime
或Database.PostgreSQL.Simple.Time.UTCTimestamp
應該映射到timestamptz
類型的PostgreSQL
。顯然,如果我得到上述錯誤,那麼這種理解就是錯誤的。將欣賞這個幫助。
已解決,謝謝! – Sal