Skip to content

Long column identifiers in deeply nested joins cause fields to be omitted #7513

@maxwey

Description

@maxwey

GORM Playground Link

go-gorm/playground#815

Description

Context

In Postgres, query column identifiers are subject to Postgres' 63 character limit. While Postgres will accept queries with identifiers that are longer than this limit, the query response will truncate the identifier to the 63 character limit.

This has an impact on Gorm when it attempts to map a query response back into a struct.

Failing Use Case -- As Demonstrated in Playground Test Case

I have added a test case with a doubly nested entity. The test case expects the international_code field to be populated following the join query, but it is "". This is a silent error.

This happens because the generated SQL query to retrieve this column is:

`CurrentEmployerInformation__PreferredCompanyLanguage`.`international_code` AS `CurrentEmployerInformation__PreferredCompanyLanguage__international_code`

CurrentEmployerInformation__PreferredCompanyLanguage__international_code is larger than 63 characters long.

Postgres accepts this in the query correctly, but returns a truncated identifier for this column that is 63 characters long. Because of the truncation, Gorm cannot map the data to its intended column, leaving it empty.

Note that this happens silently; other columns are still populated. Using the NamingStrategy with max length = 63 does not affect the identifier length in query building, and thus does not address this issue.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions