i'm trying to get a functional index to work on an email address

a table:
  class EmailAddress(DeclaredTable):
    __tablename__ = 'email_address'
    id = sa.Column(sa.Integer, primary_key=True)
    address = sa.Column(sa.Unicode(255), nullable=False)

which would have in postgres a command like:
  sql= """CREATE UNIQUE INDEX email_address_uidx ON
email_address(lower(address));"""

the purpose of which, is so the postgres query planner searches
against the pre-cached version of email_address.lower() it makes, if i
"""SELECT * FROM email_address WHERE address =
lower(%s)""" ( significantly faster than """WHERE lower(address) =
lower(%s)""" )

Reading up on the mailing list and the docs, I can see that through
the usage of event listeners, I can use a DDL to accomplish this.
which is totally ine fine.

I'm just wondering though...  wouldn't it make sense to have an
__event_name__ attribute on declared tables, which could be called
during routines ?

the current implementation works, and I'm not arguing with it -- its
very useful and powerful.  i'm just looking at how i'd structure
code... and it I'd end up with bits and pieces of a single section in
multiple locations.  it seems to me like this approach could help
centralize managing stuff.

ie

  class EmailAddress(DeclaredTable):
    __tablename__ = 'email_address'
    __after_create__ = ["""CREATE UNIQUE INDEX email_address_uidx ON
email_address(lower(address));""", self._other ]
    def _other(self):
       pass
    id = sa.Column(sa.Integer, primary_key=True)
    address = sa.Column(sa.Unicode(255), nullable=False)

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to