default index names can cause collisions in postgres

Issue #162 resolved
Former user created an issue

given (under postgres)

table_a = Table('table_a', __engine__, 
    Column('id', Integer, primary_key=True),
    Column('name', String(255) , unique=True ),
)

table_b = Table('table_b', __engine__, 
    Column('id', Integer, primary_key=True),
    Column('name', String(255) , unique=True ),
)

both will try to create 'ux_name' as the unique index

an easy workaround is to just explictly state the name of the index

it would be nice though, if sqlalchemy used the same approach that some of the pg admin interfaces use

##tablename####colname##__idx ##tablename####colname##__uidx

so instead of getting 'ux_name' we would have 'table_b__name__uidx'

i've seen some projects use and some use _ as the delimiter. i kind of like

this would make a great enhancement.

Comments (3)

  1. Former user Account Deleted

    I forgot to encapsulate some of the above to be wikisafe

    ##tablename##__##colname##__idx
    ##tablename##__##colname##__uidx
    
    so instead of getting 'ux_name' we would have 'table_b__name__uidx'
    
    i've seen some projects use __ and some use _ as the delimiter.  i kind of like __
    
  2. Former user Account Deleted

    sorry to do this in 3 parts...

    i just wanted to add what the defaults are for the postgres commandline client, in case some people are more preferential to that (i'm not. i like the __ and idx )

      primary key
      ##tablename##_##colname##_pkey
    
      unique
      ##tablename##_##colname##_key
    
  3. Log in to comment