PostgreSQL 函数上的简单“执行”失败并显示 "execute resulted in Col 1-column result"
PostgreSQL-simple `execute` on a function fails with "execute resulted in Col 1-column result"
我想从 Haskell 执行一个 Postgres 函数,它更新 3 行但用 RETURNS VOID
声明。我运行函数如下:
catch (do execute conn "select record(?,?)" [id1, id2])
(\(e :: SomeException) -> do putStrLn ("Exception:" ++ (show e)); return False)
但这会导致:
QueryError {qeMessage = "execute resulted in Col 1-column result", qeQuery = "select record(?,?)"}
查询没有 return 结果:
ebdb=> select record('','');
record
--------------------
(1 row)
如何从 Haskell 执行此 Postgresql 函数?
这个棘手的查询returns没有行,仍然执行函数:
select 1 where record('', '') isnull;
我会尝试使用 query
而不是 execute
:
query conn "select 1 from record(?,?)" [id1, id2]
execute
适用于 INSERT
、UPDATE
等语句。即使您的语句没有 return 任何行,它仍然是 SELECT
所以我认为你需要使用 query
到 运行 它。
我遇到了这个错误并发现了这个问题,但无法切换到 query
,因为我使用的库使用 execute
进行数据库迁移。 (我需要 empty/no-op 迁移。)
这是我最终使用的有效方法:
UPDATE arbitrary_but_real_table_name
SET arbitrary_text_column = 'this will not happen'
WHERE 'this is not null' IS NULL;
希望这对某人有所帮助!
我想从 Haskell 执行一个 Postgres 函数,它更新 3 行但用 RETURNS VOID
声明。我运行函数如下:
catch (do execute conn "select record(?,?)" [id1, id2])
(\(e :: SomeException) -> do putStrLn ("Exception:" ++ (show e)); return False)
但这会导致:
QueryError {qeMessage = "execute resulted in Col 1-column result", qeQuery = "select record(?,?)"}
查询没有 return 结果:
ebdb=> select record('','');
record
--------------------
(1 row)
如何从 Haskell 执行此 Postgresql 函数?
这个棘手的查询returns没有行,仍然执行函数:
select 1 where record('', '') isnull;
我会尝试使用 query
而不是 execute
:
query conn "select 1 from record(?,?)" [id1, id2]
execute
适用于 INSERT
、UPDATE
等语句。即使您的语句没有 return 任何行,它仍然是 SELECT
所以我认为你需要使用 query
到 运行 它。
我遇到了这个错误并发现了这个问题,但无法切换到 query
,因为我使用的库使用 execute
进行数据库迁移。 (我需要 empty/no-op 迁移。)
这是我最终使用的有效方法:
UPDATE arbitrary_but_real_table_name
SET arbitrary_text_column = 'this will not happen'
WHERE 'this is not null' IS NULL;
希望这对某人有所帮助!