Issue #149 wontfix

Passing [] as params to #exec when using multiple commands raises an error.

Anonymous created an issue

I noticed that when executing the following:

# Create the connection
....

query = 'SET statement_timeout=1; SHOW statement_timeout;'
connection.exec(query)

returns a proper result:

{
    "statement_timeout" => "1ms"
}

However if you execute the following:

# Create the connection
....

query = 'SET statement_timeout=1; SHOW statement_timeout;'
connection.exec(query, [])

You get the following error:

PG::Error:
       ERROR:  cannot insert multiple commands into a prepared statement

Does anyone else have the same issue? Is this on purpose? If it is, why?

Comments (2)

  1. Michael Granger repo owner

    This happens because passing parameters to PG::Connection#exec causes it to use PQexecParams() (which doesn't support multiple SQL commands) instead of PQexec(). This is a limitation imposed by the driver itself, so it's intentional that 'pg' should do the same thing.

    See the documentation for PQexecParams for details and rationale.

  2. Log in to comment