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 (6)

  1. Anonymous

    Now I see Indeed.

    http://www.postgresql.org/docs/8.3/static/textsearch-features.html

    You're right. It works better by using fts anyway.

    Thanks.

    ''cherry on top out of initial topic''

    • Is it possible without calling pure sql in a close future to get the search rank / order by rank implicit (don't seem trivial too me) ?

    • is there a doc on the clean way to implement the "basic" regexp search by declaring an operator somewhere ?

  2. Mike 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())
    
  3. Log in to comment