juliotrigo/sqlalchemy-filters

Type casting support in filters

Closed this issue · 1 comments

When attempting to filter on the id of a model with UUID as the type, I receive the error:

psycopg2.errors.UndefinedFunction: operator does not exist: uuid ~~* unknown
LINE 3: ...a-556b4fc5b33c'::uuid AND my_table.id ILIKE '123...

Could we, perhaps, supply a cast value in the filter entry, or, even better, dynamically detect the type of the column and provide the coercion, as done in SqlAlchemy Coercion

Providing an explicit type cast as:

filters = [{'field': 'id', 'op': 'ilike', 'value': '123%', 'cast': 'uuid'}]

...to generate the SQL:

WHERE my_table.id ILIKE '123%'::uuid

After sleeping on this, performing a fuzzy search on a UUID doesn't make any sense.