gpt4 book ai didi

postgresql - count(*) 类型与 Database.PostgreSQL.Simple 的兼容性错误?

转载 作者:行者123 更新时间:2023-11-29 11:29:30 24 4
gpt4 key购买 nike

错误是

*** Exception: Incompatible {errSQLType = "int8", errHaskellType = "Int", errMessage = "types incompatible"}

看起来查询中 count(*) 返回的任何值都必须转换为 Integer 而不是 Int。如果我将这些特定变量更改为 Integer 类型,查询将起作用。

但此错误并没有在另一台具有完全相同代码的机器上出现。第一台机器是 32 位的,另一台是 64 位的。这是我能辨别的唯一区别。

有没有人知道发生了什么事?

最佳答案

PostgreSQL count() 函数返回一个 Bigint 类型,参见

http://www.postgresql.org/docs/9.2/static/functions-aggregate.html

Bigint 是 8 个字节 见http://www.postgresql.org/docs/9.2/static/datatype-numeric.html

Haskell int 是 ~ 2**29 这意味着它是一个 4 字节整数。

http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Int.html

那么 PostgreSQL 或其 API 不会在精度上进行隐式向下转换是正常的。

所以使用 Haskell int64 类型或将 count(*) 转换为整数。

关于postgresql - count(*) 类型与 Database.PostgreSQL.Simple 的兼容性错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16991220/

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