diff --git a/res/res_config_pgsql.c b/res/res_config_pgsql.c
index 27494a12fbed885ccbd8e203bf31d2805daeaa46..58925a0762b4c84febc91968a25e5158ba2f140c 100644
--- a/res/res_config_pgsql.c
+++ b/res/res_config_pgsql.c
@@ -921,7 +921,7 @@ static int update2_pgsql(const char *database, const char *tablename, const stru
 static int store_pgsql(const char *database, const char *table, const struct ast_variable *fields)
 {
 	RAII_VAR(PGresult *, result, NULL, PQclear);
-	Oid insertid;
+	int numrows;
 	struct ast_str *buf = ast_str_thread_get(&escapebuf_buf, 256);
 	struct ast_str *sql1 = ast_str_thread_get(&sql_buf, 256);
 	struct ast_str *sql2 = ast_str_thread_get(&where_buf, 256);
@@ -978,10 +978,10 @@ static int store_pgsql(const char *database, const char *table, const struct ast
 	        return -1;
         }
 
-	insertid = PQoidValue(result);
+	numrows = atoi(PQcmdTuples(result));
 	ast_mutex_unlock(&pgsql_lock);
 
-	ast_debug(1, "PostgreSQL RealTime: row inserted on table: %s, id: %u\n", table, insertid);
+	ast_debug(1, "PostgreSQL RealTime: row inserted on table: %s.", table);
 
 	/* From http://dev.pgsql.com/doc/pgsql/en/pgsql-affected-rows.html
 	 * An integer greater than zero indicates the number of rows affected
@@ -989,8 +989,9 @@ static int store_pgsql(const char *database, const char *table, const struct ast
 	 * -1 indicates that the query returned an error (although, if the query failed, it should have been caught above.)
 	 */
 
-	if (insertid >= 0)
-		return (int) insertid;
+	if (numrows >= 0) {
+		return numrows;
+	}
 
 	return -1;
 }