gpt4 book ai didi

postgresql - 如何使用 postgresql-simple 检索 JSON jsonb 值?

转载 作者:行者123 更新时间:2023-12-05 03:56:26 25 4
gpt4 key购买 nike

我在 postgresql 数据库中有一列 (jsonExample),类型为 jsonb

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 或其他东西?

最佳答案

查看此处的 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"

关于postgresql - 如何使用 postgresql-simple 检索 JSON jsonb 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59314764/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com