This project is archived and is in readonly mode.
add_index on postgresql with long index names: migrations fail with Input string is longer than NAMEDATALEN-1 (63)
Reported by David Lee | September 24th, 2009 @ 01:16 AM
as of 2.3.4, migration will error out if the autogenerated index name is longer than 64 chars with:
Input string is longer than NAMEDATALEN-1 (63)
Previously, such long index names would be truncated (and appear so in schema.rb) but not cause an error.
Some discussion here: http://railsforum.com/viewtopic.php?id=33704 identifies the cause of the problem:
quote
I looked at the rails source code and the function that builds the index name, add_index() in schema_statements.rb, has not changed between versions 2.2.2 and 2.3.3. However postgresql_adapter.rb's function quote_column_name() now invokes pgconn_s_quote_ident() in ruby-pg, which performs the check on NAMEDATALEN.
endquote
Comments and changes to this ticket
-
CancelProfileIsBroken September 25th, 2009 @ 11:51 AM
- Tag changed from 2.3.4, add_index, migrations, postgresql to 2.3.4, add_index, bugmash, migrations, postgresql
-
Sebastian A. Espindola September 25th, 2009 @ 04:09 PM
This work has bitten me to.
I verified the same behaviour with the postgres driver
when trying to create a 4 fields long composite index.
I'm working on a patch to truncate index names to the max
identifier size.Will have it uploaded in a couple hours.
-
Ben Woodcroft September 26th, 2009 @ 01:29 AM
For me, the same thing occurs for remove_index, presumably for the same reason. As with add_index, using the :name option worked around it.
-
Ben Woodcroft January 2nd, 2010 @ 05:44 AM
- Tag changed from 2.3.4, add_index, bugmash, migrations, postgresql to 2.3.4, 2.3.5, add_index, bugmash, migrations, postgresql
still true as of 2.3.5
-
Matt Jones January 4th, 2010 @ 07:18 PM
There's a more general issue where the AR adapters don't have any details about the various adapter's limits; see #3452 for a patch I'm working on to clean up the behavior of add_index and friends. It needs some rewriting, but could be useful in cases like this.
BTW, is there a coherent place where these limits are defined for PG? I had a heck of a time trying to find documentation for any of the supporting DBs that actually specified hard limits.
-
Rizwan Reza February 12th, 2010 @ 12:46 PM
- Tag changed from 2.3.4, 2.3.5, add_index, bugmash, migrations, postgresql to 2.3.4, 2.3.5, add_index, migrations, postgresql
-
Incite March 23rd, 2010 @ 12:23 AM
You can find PG defaults in pg_config_manual.h which should generally be available since you need postgres headers to install the gem. Specifically, NAMEDATALEN
-
Jeremy Kemper April 23rd, 2010 @ 06:04 PM
- State changed from new to duplicate
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Referenced by
- 3508 Limit MySQL index name length Hrm.. the PostgreSQL adapter seems to have similar trunca...
- 3508 Limit MySQL index name length There is a patch in #3452 which was mentioned in #3252 li...
- 3452 [PATCH] Improve DB index handling Ok so I read #3252 and #3508 which made me realize Postgr...
- 6187 PostgreSQL and Rails 3.0.3 migrations fail with index name length > 64 chars I understand that PG cuts it off, but doesn't it make mor...
- 6187 PostgreSQL and Rails 3.0.3 migrations fail with index name length > 64 chars rails < 2.3.4 didn't care 2.3.4 <= rails < 2.3.6 - except...