Skip to content

Repro for postgres deep nested joins #815

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

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