我在postgresql数据库中有一个类型为jsonb的列(jsonExample)。
selectCALogs :: IO [(Int, Object)]
selectCALogs = do
con <- connection
query_ con "select \"clusterId\", \"jsonExample\" from cluster"这会产生以下错误:
• No instance for (Database.PostgreSQL.Simple.FromField.FromField
(unordered-containers-0.2.10.0:Data.HashMap.Base.HashMap
Text Value))
arising from a use of ‘query_’
• In a stmt of a 'do' block:
query_ con "select \"clusterId\", \"clusterCALogs\"
from cluster"
In the expression:
do con <- connection
query_ con "select \"clusterId\", \"clusterCALogs\"from cluster"
In an equation for ‘selectCALogs’:
selectCALogs
= do con <- connection
query_ con "select \"clusterId\",
\"clusterCALogs\" from cluster"
|
80 | query_ con "select \"clusterId\", \"clusterCALogs\"
from cluster"
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^我怎样才能让它返回一个JSON对象--使用aeson还是别的什么?
发布于 2019-12-14 01:16:16
看看这里的FromField实例(http://hackage.haskell.org/package/postgresql-simple-0.6.2/docs/Database-PostgreSQL-Simple-FromField.html#t:FromField),我意识到它应该是Value而不是Object。
因此:
selectCALogs :: IO [(Int, Value)]
selectCALogs = do
con <- connection
query_ con "select \"clusterId\", \"jsonExample\" from cluster"https://stackoverflow.com/questions/59314764
复制相似问题