haskell-postgres - > connect参数不是Query

时间:2015-04-26 01:38:22

标签: postgresql haskell

我的节目:

import Database.PostgreSQL.Simple

main :: IO ()
main = do
  conn <- connect defaultConnectInfo
    { connectUser = "postgres"
      , connectPassword = "password"
      , connectDatabase = "postgres"
    }
  execute conn "create table users (id INT, fname VARCHAR(80), lname VARCHAR(80))" ()
  close conn

错误:

Couldn't match expected type ‘Query’ with actual type ‘[Char]’
    In the second argument of ‘execute’, namely
      ‘"create table users (id INT, fname VARCHAR(80), lname VARCHAR(80))"’

用户是否需要将上述psql字符串转换为Query类型对象并将其作为参数发送给connect函数?本教程不是以这种方式编写的,但错误是其他意思。

1 个答案:

答案 0 :(得分:3)

来自the docs

  

要最轻松地构建查询,请启用GHC的OverloadedStrings语言扩展,并将查询编写为普通文字字符串。

OverloadedStrings可让您撰写看似String的内容并让GHC自动将其强制转换为相应的类型(ByteStringText,{{1} })。这是保存在工具箱中的有用扩展。