Skip to content

spanner: SelectAll does not use the same field matching rules as Row.ToStruct #9415

@CAFxX

Description

@CAFxX

Assume a table like

		CREATE TABLE test (
			id INT64 NOT NULL,
			name STRING(MAX),
		) PRIMARY KEY (id);

Expected behavior

SelectAll, when passed a slice of

struct {
		ID   int64 
		Name string
}

should behave like Row.ToStruct, and perform case-insensitive comparison between the column name and the field name. In this case, this means mapping the id column to the ID field, and the name column to the Name field.

Actual behavior

Contrary to Row.ToStruct, SelectAll does not perform a case-insensitive compare, and thus returns the error Go struct {ID:0 Name:}(type reflect.Value) has no or duplicate fields for Cloud Spanner STRUCT field id.

Adding field tags like

struct {
		ID   int64  `spanner:"id"`
		Name string `spanner:"name"`
}

makes the problem go away, but Row.ToStruct does not require them.

Metadata

Metadata

Assignees

Labels

api: spannerIssues related to the Spanner API.triage meI really want to be triaged.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions