Get count of records affected by INSERT or UPDATE in PostgreSQL

前端 未结 5 1512
挽巷
挽巷 2020-12-01 09:13

My database driver for PostgreSQL 8/9 does not return a count of records affected when executing INSERT or UPDATE.

PostgreSQL offers the n

5条回答
  •  囚心锁ツ
    2020-12-01 09:29

    It's not clear from your question how you're calling the statement. Assuming you're using something like JDBC you may be calling it as a query rather than an update. From JDBC's executeQuery:

    Executes the given SQL statement, which returns a single ResultSet object.

    This is therefore appropriate when you execute a statement that returns some query results, such as SELECT or INSERT ... RETURNING. If you are making an update to the database and then want to know how many tuples were affected, you need to use executeUpdate which returns:

    either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing

提交回复
热议问题