0

I am trying to execute a prepared statement in PostgreSQL using the pg gem in Ruby. I am using the conn.prepare method to prepare the statement, and exec_prepared to execute the statement with the parameters. However, I am getting the following error:

wrong number of arguments (given 1, expected 2..3) (ArgumentError)

Here is the offending code:

conn = PG.connect(host: 'localhost', dbname: 'mydb', password: 'password')
stmt = conn.prepare("SELECT id FROM websites WHERE url = $1")
result = stmt.exec_prepared('myurl')

I have checked and the table and column exist, and the user I am connecting to the database has the proper permissions to execute a SELECT statement on the table. Also, checked that the statement works in the PostgreSQL cli to be double sure. I am not sure why I am getting this error. Can anyone help me understand what is causing this and how to fix it?

Ali Ove
  • 71
  • 7

0 Answers0