Search code examples
rubyprepared-statementpg

Ruby `prepare': ERROR: prepared statement "should_insert" already exists (PG::DuplicatePstatement)


I've looked the link

How to fix PG::DuplicatePstatement: ERROR?

but it still did not solve the error message I'm getting

`prepare': ERROR:  prepared statement "should_insert" already exists (PG::DuplicatePstatement)

Where do I put the block of code from the answer in the above link? Do I have to call a method in order for it to execute?

db_connection = PGconn.connect("localhost", 5433, '', '', "dev_ddb", "user", "pass")

db_connection.prepare('should_insert', 'SELECT COUNT(*) from users where user_id = $1')

Solution

  • I was able to get this working by deallocating the prepared statement. I inserted this line right after the exec_prepared statement.

    db_connection.exec("DEALLOCATE should_insert")