1. Michael Bayer
  2. sqlalchemy
  3. Issues

Issues

Issue #1390 new

postgresql regular expression operators

Anonymous created an issue

match operator not implemented

in sqlalchemy/databases/postgres.py 727 just add sql_operators.match_op: lambda x, y, escape=None: '%s ~ %s' % (x, y) + (escape and ' ESCAPE \'%s\'' % escape or ''),

and it works for me CAVEAT sql might crash if improper regexp syntax entered.

  • missing imatch / notmatch ....

(these matching functions are still used with same syntax) http://www.postgresql.org/docs/7.4/interactive/functions-matching.html

Comments (10)

  1. Michael Bayer repo owner

    demo (using attached patch):

    from sqlalchemy import *
    from sqlalchemy.dialects import postgresql
    
    metadata = MetaData()
    
    t = Table('t', metadata,
        Column('x', postgresql.VARCHAR(30))
    )
    
    
    print t.c.x.regexp("foo").compile(dialect=postgresql.dialect())
    print (~t.c.x.regexp("foo")).compile(dialect=postgresql.dialect())
    print (~t.c.x.iregexp("foo")).compile(dialect=postgresql.dialect())
    
  2. Log in to comment