postgresql-简单的查询错误 [英] postgresql-simple query error
问题描述
psql
中执行该查询时,我得到以下结果: lwm @ verbos
=#SELECT * FROM gerund LIMIT1;
不定式│gerund│gerund_english
────────────┼───────────────────────── ───────
放弃│放弃│放弃
所以, 3串?但是,我说我回来 IO [Only String]
。我确信这是我的类型签名,这是搞砸的事情...
我试图使用 postgresql-简单的
库包含 Haskell
。我的代码与我看到的错误一起粘贴在下面。任何人有任何想法?
我的数据库被称为 给我以下错误: ConversionFailed {errSQLType =3 values:[(Basic {typoid = Oid 1043, 好的,感谢@AlpMestanogullari,@ muistooshort,我在这里得到了答案。我的最终代码是: 注意: EDIT: I now have a better idea of what is going wrong. When I perform that query in plain old So, I am getting back 3 strings? However, I say that I am getting back I am trying to make a simple query using the My database is called Gives me the following error: ConversionFailed {errSQLType = "3 values: [(Basic {typoid = Oid 1043,
typcategory = 'S', typdelim = ',', typname = \"varchar\"},Just
\"abandonar\"),(Basic {typoid = Oid 1043, typcategory = 'S', typdelim
= ',', typname = \"varchar\"},Just \"abandonando\"),(Basic {typoid = Oid 1043, typcategory = 'S', typdelim = ',', typname =
\"varchar\"},Just \"abandoning\")]", errSQLTableOid = Nothing,
errSQLField = "", errHaskellType = "1 slots in target type",
errMessage = "mismatch between number of columns to convert and number
in target type"}
OK, Thanks to @AlpMestanogullari, @muistooshort, I got an answer here. My final code is: Notes: 这篇关于postgresql-简单的查询错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! verbos
并且在其中有一个名为动名词
。我能够运行一个查询_
,它包含: connSELECT 2 + 2
,并且工作正常。我也可以使用缺省信息(password ='postgres': psql -h localhost -p 5432 -U postgres
(来自docs [ 1
$ b $ pre $ { - #LANGUAGE OverloadedStrings# - }
模块Main其中
import Control.Monad
import Control.Applicative
import Database.PostgreSQL.Simple
main = do
conn< - connect defaultConnectInfo {
connectPassword =postgres,
connectDatabase =verbos
}
mapM_ print =<(query_connSELECT * FROM gerund LIMIT 1:: IO [ )
typcategory =' S',typdelim =',',typname = \varchar \},只需
\abandonar \),(Basic {typoid = Oid 1043,typcategory ='S',typdelim
=',',typname = \varchar \},Just \abandonando\),(Basic {typoid = Oid 1043,typcategory ='S',typdelim =',',typname =
\varchar \},只是\abandoning \)],errSQLTableOid = Nothing,
errSQLField =,errHaskellType =目标类型中有1个槽位,
errMessage =目标类型转换的列数与
的数目不匹配} b $ b
{ - #LANGUAGE OverloadedStrings# - }
模块Main其中
导入Control.Applicative
导入Database.PostgreSQL.Simple
导入Database.PostgreSQL.Simple.FromRow
数据Gerund = Gerund {
f: :String,
s :: String,
t :: String
}派生(显示)
实例FromRow Gerund其中
fromRow = Gerund< $> ;字段< *>字段< *>字段
main = do
conn< - connect defaultConnectInfo {
connectPassword =postgres,
connectDatabase =verbos
}
mapM_print =<< (query_conn q :: IO [Gerund])
where q =SELECT * FROM gerund LIMIT 1
类型,结果有'空格'(
f
, s
和<$ c $在 Gerund
类型中)
类型
和实例
。
import Database.PostgreSQL.Simple.FromRow
才能访问字段
。
psql
, I get the following result:lwm@verbos
=# SELECT * FROM gerund LIMIT1;
infinitive │ gerund │ gerund_english
────────────┼─────────────┼────────────────
abandonar │ abandonando │ abandoning
IO [Only String]
. I am sure it is my type signature here that is messing things up ...postgresql-simple
library with Haskell
. My code is pasted below along with the error I am seeing. Anyone got any ideas?verbos
and within it, I have a table called gerund
. I am able to run a query_
that contains: conn "SELECT 2 + 2"
and that works fine. I can also connect to my database with the default data as specified with the default information (password = 'postgres' : psql -h localhost -p 5432 -U postgres
(from the docs[1]){-# LANGUAGE OverloadedStrings #-}
module Main where
import Control.Monad
import Control.Applicative
import Database.PostgreSQL.Simple
main = do
conn <- connect defaultConnectInfo {
connectPassword = "postgres",
connectDatabase = "verbos"
}
mapM_ print =<< (query_ conn "SELECT * FROM gerund LIMIT 1" :: IO [Only String])
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Control.Applicative
import Database.PostgreSQL.Simple
import Database.PostgreSQL.Simple.FromRow
data Gerund = Gerund {
f :: String,
s :: String,
t :: String
} deriving (Show)
instance FromRow Gerund where
fromRow = Gerund <$> field <*> field <*> field
main = do
conn <- connect defaultConnectInfo {
connectPassword = "postgres",
connectDatabase = "verbos"
}
mapM_ print =<< (query_ conn q :: IO [Gerund])
where q = "SELECT * FROM gerund LIMIT 1"
type
that had 'space' for the results (f
, s
and t
in the Gerund
type)type
and instance
defined. import Database.PostgreSQL.Simple.FromRow
to access things like field
.