Skip to content
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

Add a check for identifiers with maximum length #196

Open
mfvanek opened this issue Feb 8, 2023 · 2 comments
Open

Add a check for identifiers with maximum length #196

mfvanek opened this issue Feb 8, 2023 · 2 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@mfvanek
Copy link
Owner

mfvanek commented Feb 8, 2023

By default identifier length is bounded with 63 bytes.
When any identifier (table/index/sequence name) is out of this range PostgreSQL will silently truncate the identifier name. No errors are raised.
It might be confusing for developers in case of two identifiers with long names that differ a bit at the ending:

create index concurrently if not exists my_custom_index_on_my_custom_table_with_very_loooooooooooooooooooong_name_on_field1
    on my_custom_table (field1);
create index concurrently if not exists my_custom_index_on_my_custom_table_with_very_loooooooooooooooooooong_name_on_field2
    on my_custom_table (field2);

For first index you will get a warning with sql state 42622 like:
identifier "my_custom_index_on_my_custom_table_with_very_loooooooooooooooooooong_name_on_field1" will be truncated to "my_custom_index_on_my_custom_table_with_very_looooooooooooooooo"
and index will be created with truncated name.

For second index you'll get a warning:
relation "my_custom_index_on_my_custom_table_with_very_looooooooooooooooo" already exists, skipping and no index

@mfvanek mfvanek added enhancement New feature or request help wanted Extra attention is needed labels Feb 8, 2023
@mfvanek
Copy link
Owner Author

mfvanek commented Feb 8, 2023

Flyway with Teams subscription probably can help. See Error Overrides option:
.errorOverrides("42622:0:E")

@mfvanek
Copy link
Owner Author

mfvanek commented May 4, 2024

We can find all identifiers with maximum length and report them.
It will not be a very accurate check but sometimes it can be useful.

@mfvanek mfvanek changed the title Consider to add a check for identifiers length in sql migrations Add a check for identifiers with maximum length May 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant