Skip to content

Breaking change in fieldPosByName() #2296

@bellajones12

Description

@bellajones12

Describe the bug
Breaking change in fieldPosByName() from PR RowToStructByName Snake Case Collision #2085 in rows.go line 831. [https://github.com//pull/2085/files]
Changed from: if strings.EqualFold(descName, field) { return i

to: if desc.Name == field { return i }

This leads it to return correctly when cases are different.

To Reproduce
For this struct:
type structname struct {
RegionsStr string db:"Region"
}

and this query:

SELECT
string_agg(distinct c.region, ', ') as Region

returns an error as we cast the variable as uppercase. As desc.Name is lowercase, desc.Name == field incorrectly returns an error.

Expected behavior
The variables should be matched regardless of the case, like this if strings.EqualFold(descName, field) { return i

Actual behavior
If variables are a different case, an error is returned.

Version

  • Go: go1.24.1 linux/arm64
  • PostgreSQL: PostgreSQL 13.20 on x86_64-pc-linux-gnu, compiled by Debian clang version 12.0.1, 64-bit
  • pgx: github.com/jackc/pgx/v5 v5.7.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions