title: Python/postgres/psycopg2: getting ID of row just inserted
body: <p>I'm using Python and psycopg2 to interface to postgres. </p>
  
  <p>When I insert a row...</p>
  
  <pre><code>sql_string = "INSERT INTO hundred (name,name_slug,status) VALUES ("
  sql_string += hundred_name + ", '" + hundred_slug + "', " + status + ");"
  cursor.execute(sql_string)
  </code></pre>
  
  <p>... how do I get the ID of the row I've just inserted? Trying:</p>
  
  <pre><code>hundred = cursor.fetchall() 
  </code></pre>
  
  <p>returns an error, while using <code>RETURNING id</code>:</p>
  
  <pre><code>sql_string = "INSERT INTO domes_hundred (name,name_slug,status) VALUES ("
  sql_string += hundred_name + ", '" + hundred_slug + "', " + status + ") RETURNING id;"
  hundred = cursor.execute(sql_string)
  </code></pre>
  
  <p>simply returns <code>None</code>. </p>
  
  <p>UPDATE: So does <code>currval</code> (even though using this command directly into postgres works): </p>
  
  <pre><code>sql_string = "SELECT currval(pg_get_serial_sequence('hundred', 'id'));"
  hundred_id = cursor.execute(sql_string)
  </code></pre>
  
  <p>Can anyone advise?</p>
  
  <p>thanks!</p>