Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

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)

#3252

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

Reported by David Lee · September 24th, 2009 @ 01:16 AM

State: duplicate
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. CancelProfileIsBroken
    CancelProfileIsBroken
    • Tag changed from 2.3.4, add_index, migrations, postgresql to 2.3.4, add_index, bugmash, migrations, postgresql

    September 25th, 2009 @ 11:51 AM

  2. Sebastian A. Espindola
    Sebastian A. Espindola

    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.

    September 25th, 2009 @ 04:09 PM

  3. Ben Woodcroft
    Ben Woodcroft

    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.

    September 26th, 2009 @ 01:29 AM

  4. Ben Woodcroft
    Ben Woodcroft
    • 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

    January 2nd, 2010 @ 05:44 AM

  5. Matt Jones
    Matt Jones

    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.

    January 4th, 2010 @ 07:18 PM

  6. Rizwan Reza
    Rizwan Reza
    • 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

    February 12th, 2010 @ 12:46 PM

  7. Incite
    Incite

    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

    March 23rd, 2010 @ 12:23 AM

  8. Jeremy Kemper
    Jeremy Kemper
    • State changed from new to duplicate

    April 23rd, 2010 @ 06:04 PM