postgresql regular expression operators

Issue #1390 new
Former user 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 Trier

    Except you'll have to specify something other than match_op since we're using that for the Full Text Searching.

  2. Former user Account Deleted

    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 ?

  3. 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())
    
  4. Mike Bayer repo owner
    • edited description
    • changed milestone to 1.3

    1.3 for the moment, the gerrit needs some work and this is not crtiical

  5. Log in to comment