Skip to content

Conversation

maxwey
Copy link

@maxwey maxwey commented Jul 11, 2025

Explain your user case and expected results

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.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant