我想执行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(?,?)"}
查询不返回结果:
ebdb=> select record('','');
record
--------------------
(1 row)
如何从Haskell执行这个Postgresql函数?
我会尝试使用query
而不是execute
:
query conn "select 1 from record(?,?)" [id1, id2]
execute
用于INSERT
、UPDATE
等语句。即使您的语句没有返回任何行,但它仍然是SELECT
,所以我认为您需要使用query
来运行它。
这个棘手的查询没有返回行,但函数仍在执行:
select 1 where record('', '') isnull;
我收到了这个错误并找到了这个问题,但无法切换到query
,因为我使用的库使用execute
进行数据库迁移。(我需要一个空的/无操作的迁移。)
以下是我最终使用的有效方法:
UPDATE arbitrary_but_real_table_name
SET arbitrary_text_column = 'this will not happen'
WHERE 'this is not null' IS NULL;
希望这能帮助到别人!