--- src/dm_db.c +++ src/dm_db.c @@ -511,16 +511,19 @@ assert(r); db_result_next(r); - // lastRowId is always zero for pgsql tables without OIDs - // or possibly for sqlite after calling executeQuery but - // before calling db_result_next - - if ((id = (uint64_t )Connection_lastRowId(c)) == 0) { // mysql - // but if we're using 'RETURNING id' clauses on inserts - // or we're using the sqlite backend, we can do this - + if (db_params.db_driver == DM_DRIVER_POSTGRESQL) + { + id = db_result_get_u64(r, 0); + } + else + { + // lastRowId is always zero for pgsql tables without OIDs + // or possibly for sqlite after calling executeQuery but + // before calling db_result_next + if ((id = (uint64_t )Connection_lastRowId(c)) == 0) // sqlite id = db_result_get_u64(r, 0); // postgresql + id = (uint64_t )Connection_lastRowId(c); } assert(id); return id;