0

I want to execute a Postgres function from Haskell which updates 3 rows but is declared with RETURNS VOID. I run the function as follows:

catch (do execute conn "select record(?,?)" [id1, id2])
      (\(e :: SomeException) -> do putStrLn ("Exception:" ++ (show e)); return False)

but this results in:

QueryError {qeMessage = "execute resulted in Col 1-column result", qeQuery = "select record(?,?)"}

The query doesn't return results:

ebdb=> select record('','');
 record
--------------------

(1 row)

How can I execute this Postgresql function from Haskell?

Chris Stryczynski
  • 30,145
  • 48
  • 175
  • 286
Alex
  • 8,093
  • 6
  • 49
  • 79

3 Answers3

1

This tricky query returns no rows, still the function is executed:

select 1 where record('', '') isnull;
klin
  • 112,967
  • 15
  • 204
  • 232
1

I would try using query instead of execute:

query conn "select 1 from record(?,?)" [id1, id2]

execute is for statements like INSERT, UPDATE, etc. Even though your statement does not return any rows, it is still a SELECT so I think you need to use query to run it.

Alex
  • 8,093
  • 6
  • 49
  • 79
ErikR
  • 51,541
  • 9
  • 73
  • 124
1

I got this error and found this question but wasn't able to switch to query because I'm using a library that uses execute for database migrations. (I needed an empty/no-op migration.)

Here's what I ended up using which worked:

UPDATE arbitrary_but_real_table_name
  SET arbitrary_text_column = 'this will not happen' 
  WHERE 'this is not null' IS NULL;

Hope this helps someone!

Alex
  • 8,093
  • 6
  • 49
  • 79
Libby
  • 1,357
  • 12
  • 17