Skip to content

DML with RETURNING statements do not return update count / affected rows #777

Description

@olavloite

Description

When executing a DML statement containing a RETURNING clause (e.g., INSERT INTO table ... RETURNING id), RecordsAffected returns 0 instead of the actual number of rows inserted/updated.

Root Cause

  1. In Cloud Spanner, DML statements with a RETURNING clause are executed as queries (returning a row stream).
  2. The Google Cloud Spanner Go client library (google-cloud-go) does not populate the RowCount field on query row iterators (unlike standard DML iterators).
  3. The Go SQL proxy driver (go-sql-spanner) relies on it.RowCount to populate the ResultSetStats.RowCountExact field. Because this field is not set by the Go client for query iterators, the Go proxy receives a row count of 0 and propagates rowCountExact: 0 back to the C# ADO.NET client.
  4. As a result, the C# client always receives 0 for RecordsAffected for DML statements with a returning clause.

Steps to Reproduce

  1. Execute a DML returning statement using ExecuteReader or ExecuteReaderAsync.
  2. Drain the reader completely.
  3. Read the RecordsAffected property. It will be 0 instead of the expected row count.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions