I am trying to add regexp and iregexp operators to a subclass of the Text type. I'm using SQLAlchemy v1.0.12.
I am able to correctly use '~' and '!~' operators if I use a notregexp method like this: import sqlalchemy.types as types class TEXT(types.Text): class Comparator(types.Text.Comparator): def regexp(self, other): return self.op('~')(other) def notregexp(self, other): return self.op('!~')(other) comparator_factory = Comparator However, I would like to correctly emit the '!~' operator if I use not_ or ~ in SQLAlchemy, so I tried to do the following: import sqlalchemy.types as types from sqlalchemy.sql.expression import BinaryExpression from sqlalchemy.sql import operators class TEXT(types.Text): class Comparator(types.Text.Comparator): def regexp(self, other): return BinaryExpression( self, other, operator=operators.custom_op('~'), type_=TEXT, negate=operators.custom_op('!~')) comparator_factory = Comparator But I can't seem to get that to work. I was attempting to copy the UnaryExpression example here <http://docs.sqlalchemy.org/en/latest/core/custom_types.html?highlight=userdefinedtype#redefining-and-creating-new-operators> . I see the patch on BitBucket <https://bitbucket.org/zzzeek/sqlalchemy/issues/1390/postgresql-regular-expression-operators> for adding these operators, but I'm trying to do the same with the public API. Is it possible? Thanks, Frazer McLean -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.