Skip to content

TypeORM Postgres identifier limit is 63 bytes, column aliases get truncated #3118

@jakari

Description

@jakari

Issue type:

[ ] question
[x] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[x] postgres
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[ ] latest
[ ] @next
[x] 0.2.8

I have found that there are some issues with column aliasing when doing queries from the database. The column names might get very long inside the actual query when they concatenate the entity name into the column name. This becomes an issue in Postgres since the maximum length of a Postgres column is 63 bytes. This is especially a problem with embedded entities.

This same 63 byte name limit restriction applies to column aliases as well.

Currently, when TypeORM creates a query it creates an alias for each column it selects. The alias is of format "tablename_columnname". Now if we have a long table name and a long column name, that are both under 63 by themselves, but concatenated over 63 bytes, TypeORM won't find the column data because of the fact that Postgres also truncates the alias to 63 bytes.

A description of the limit is found in the postgres docs

This issue might not be limited to Postgres only, however I haven't tested other databases.

Steps to reproduce or a small repository showing the problem:

Repository at https://github.com/jakari/typeorm-column-length-issue

An example of the issue by doing a query in Postgres:

[typeorm_test=# SELECT "andHereWehaveAnTooLongEntityNameThatIsVeryDescriptive" AS "EntityWithVeryLongAndDescriptiveName_andHereWehaveAnTooLongEntityNameThatIsVeryDescriptive" FROM entity_with_very_long_and_descriptive_name;
NOTICE:  identifier "EntityWithVeryLongAndDescriptiveName_andHereWehaveAnTooLongEntityNameThatIsVeryDescriptive" will be truncated to "EntityWithVeryLongAndDescriptiveName_andHereWehaveAnTooLongEnti"
 EntityWithVeryLongAndDescriptiveName_andHereWehaveAnTooLongEnti
-----------------------------------------------------------------
                                                               1
(1 row)

This means that TypeORM omits this column result because it can't find the column.

Initial suggestion:

I suggest the table names could be mapped to simple numerical incremental names like:

SELECT "some_table"."some_column" AS "t0_c0, "some_other_table"."some_other_column" AS "t1_c0"

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions