title: Is there a way to inspect the query string run by asyncpg?
body: <p>When I use <a href="https://magicstack.github.io/asyncpg/current/index.html" rel="nofollow noreferrer">asyncpg</a> to run a query on my database (and I have to run several queries),<br>
  I always split up things like this:</p>
  <ul>
  <li>the string of the query, with parameters placeholders:
  <pre><code>QUERY_1 = &quot;&quot;&quot;
  UPDATE TABLE my_table 
  SET field_1 = $1
  WHERE field_id = $2;
  &quot;&quot;&quot;
  </code></pre>
  </li>
  <li>a dictionary with the query parameters:
  <pre><code>query_params_dict = { 
      &quot;field_1&quot; : &quot;value_1&quot;,
      &quot;field_id&quot; : &quot;10&quot;
  }
  </code></pre>
  </li>
  <li>and the function that will get the query string, replace the placeholders with the parameters values, run the query with <a href="https://magicstack.github.io/asyncpg/current/api/index.html?highlight=connection%20execute#asyncpg.connection.Connection.execute" rel="nofollow noreferrer">connection.execute</a>, and manage the errors:
  <pre><code>async def run_query_1(query_params_dict):
      connection = await Utils.get_connection_to_db(**conf.asyncpg_db_conn) # custom function to open the connection to my db
      query = QUERY_1
      try:
          await connection.execute(
              query, query_params_dict[&quot;field_1&quot;], int(query_params_dict[&quot;field_id&quot;])
          )
          return None
      except (Exception, asyncpg.UniqueViolationError) as integrError:
          logger.error(&quot;Violated unique constraint: {}&quot;.format(integrError), exc_info=True)
          return &quot;{}&quot;.format(integrError)
      except (Exception, asyncpg.ConnectionFailureError) as error:
          logger.error(&quot;Failed connection: {}&quot;.format(error), exc_info=True)
          return &quot;{}&quot;.format(error)
      finally:
          if (connection):
              await Utils.close_connection(connection)
  </code></pre>
  </li>
  </ul>
  <p>But the queries I have to run often require many mores parameters, so that I always make some mistake in assigning values to the variables,<br>
  so that the query fails/returns unwanted results,<br>
  and the only way I know to determine what is wrong with it, is to check carefully the value assigned to every parameter of <code>query_params_dict</code>.</p>
  <p>This takes a lot of time.<br>
  Instead, I could understand quickly what is wrong by checking the query run by asyncpg.</p>
  <p>So, <strong>is there a way to inspect the query string run by asyncpg?</strong></p>
  <p>I would expect a command of asyncpg taking the same arguments of <code>connection.execute</code> as input, and returning as output the string of the query filled up with parameters, without running any query on the database.<br>
  Let's suppose this command exists and is <code>connection.expected_query</code>, in my case it would work like this:</p>
  <pre><code>connection.expected_query(
                  query, query_params_dict[&quot;field_1&quot;], int(query_params_dict[&quot;field_id&quot;])
  &gt;&gt;&gt;
  
  &quot;&quot;&quot;
  UPDATE TABLE my_table 
  SET field_1 = 'value_1'
  WHERE field_id = 10;
  &quot;&quot;&quot;
  </code></pre>