index creation fails when table outside of 'public' schema (postgresql)

Issue #90 resolved
Former user created an issue

Attempting to create a table with a unique index fails when the table is outside of the default schema.

Executing the following code:

from sqlalchemy import *

engine = create_engine('postgres', {'database':'james'})

test_table = Table('my_table', engine,
                Column('id', Integer, primary_key=True),
                Column('data', String(20), unique=True, nullable=False),
                schema='my_schema'
             )

test_table.create()

Results in:

SQLError: (ProgrammingError) relation "my_table" does not exist

The generated SQL query looks something like:

CREATE UNIQUE INDEX ux_data ON my_table (data)

However I believe it should be

CREATE UNIQUE INDEX ux_data ON my_schema.my_table (data)

Also, I think the name 'ux_data' would collide if more than one table specified a unique index on a column named 'data'.

Comments (3)

  1. Former user Account Deleted

    I believe this problem can be fixed with the following patch, however I'm not sure if this will break anything else.

    --- ansisql.py  (revision 1097)
    +++ ansisql.py  (working copy)
    @@ -606,7 +606,7 @@
             if index.unique:
                 self.append('UNIQUE ')
             self.append('INDEX %s ON %s (%s)' \
    -                    % (index.name, index.table.name,
    +                    % (index.name, index.table.fullname,
                            string.join([for c in index.columns](c.name), ', ')))
             self.execute()
    
  2. Log in to comment