title: django last_executed_query: what is the purporse of the sql, params paremeters passed in the function
body: <p>I am working on a Django project and using Postgresql as database.</p>
  
  <p>I wanted to know what does <code>sql, params</code> do in the below function which i found at <code>/lib/python3.7/site-packages/django/db/backends/postgresql/operations.py</code></p>
  
  <pre><code>def last_executed_query(self, cursor, sql, params):
      # http://initd.org/psycopg/docs/cursor.html#cursor.query
      # The query attribute is a Psycopg extension to the DB API 2.0.
      if cursor.query is not None:
          return cursor.query.decode()
      return None
  </code></pre>
  
  <p>I found it being used at <a href="https://stackoverflow.com/a/47542953/2897115">https://stackoverflow.com/a/47542953/2897115</a></p>
  
  <pre><code>def str_query(qs):
      """
      qs.query returns something that isn't valid SQL, this returns the actual
      valid SQL that's executed: https://code.djangoproject.com/ticket/17741
      """
      cursor = connections[qs.db].cursor()
      query, params = qs.query.sql_with_params()
      cursor.execute('EXPLAIN ' + query, params)
      res = str(cursor.db.ops.last_executed_query(cursor, query, params))
      assert res.startswith('EXPLAIN ')
      return res[len('EXPLAIN '):]
  </code></pre>
  
  <p>Since <code>(sql, params)</code> or here <code>(query, params)</code> are not being used then <code>last_executed_query</code> return the same as <code>connections[qs.db][queries][-1]</code></p>