Skip to content

Returning JSON into json.RawMessage reported error: unsupported Scan #99

@shelly-li-sl

Description

@shelly-li-sl

Returning JSON into JSON.RawMessage reports the following error:

===Error:
2025/10/23 01:11:00 /scratch/shulili/GORM/gorm-github/gorm-oracle/tests/json_edge_cases_test.go:189 sql: Scan error on column index 1, name "doc": unsupported Scan, storing driver.Value type godror.JSON into type *json.RawMessage
[1.007ms] [rows:1] SELECT * FROM "returning_records" WHERE "record_id" = 1
json_edge_cases_test.go:190: returning into RawMessage failed: sql: Scan error on column index 1, name "doc": unsupported Scan, storing driver.Value type godror.JSON into type *json.RawMessage

===Code snapshot:

type ReturnedRaw struct{ Doc json.RawMessage }
	var retRaw ReturnedRaw
	if err := DB.
		Clauses(clause.Returning{Columns: []clause.Column{{Name: "doc"}}}).
		Model(&ReturningRecord{}).
		Where(`"record_id" = ?`, record.ID).
		Update("doc", gorm.Expr(`JSON_TRANSFORM("doc", SET '$.n' = 3)`)).
		Scan(&retRaw).Error; err != nil {
		t.Fatalf("returning into RawMessage failed: %v", err)
	}

===Full test case can be found in json_bulk_2_test.go(TestJSONReturning)

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